mirror of
https://github.com/essentials/Essentials.git
synced 2025-09-02 03:02:49 +02:00
Cleanup usages of split.
This commit is contained in:
@@ -10,6 +10,7 @@ import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.II18n;
|
||||
|
||||
@@ -97,6 +98,7 @@ public class I18n implements II18n
|
||||
}
|
||||
return messageFormat.format(objects);
|
||||
}
|
||||
private final Pattern partSplit = Pattern.compile("[_\\.]");
|
||||
|
||||
public void updateLocale(final String loc)
|
||||
{
|
||||
@@ -104,7 +106,7 @@ public class I18n implements II18n
|
||||
{
|
||||
return;
|
||||
}
|
||||
final String[] parts = loc.split("[_\\.]");
|
||||
final String[] parts = partSplit.split(loc);
|
||||
if (parts.length == 1)
|
||||
{
|
||||
currentLocale = new Locale(parts[0]);
|
||||
|
@@ -84,31 +84,39 @@ public class ItemDb implements IItemDb
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack get(final String id, final int quantity) throws Exception
|
||||
{
|
||||
final ItemStack retval = get(id.toLowerCase(Locale.ENGLISH));
|
||||
retval.setAmount(quantity);
|
||||
return retval;
|
||||
}
|
||||
private final Pattern idMatch = Pattern.compile("^\\d+[:+',;.]\\d+$");
|
||||
private final Pattern metaSplit = Pattern.compile("[:+',;.]");
|
||||
private final Pattern number = Pattern.compile("^\\d+$");
|
||||
private final Pattern conjoined = Pattern.compile("^[^:+',;.]+[:+',;.]\\d+$");
|
||||
|
||||
@Override
|
||||
public ItemStack get(final String id) throws Exception
|
||||
{
|
||||
int itemid = 0;
|
||||
String itemname = null;
|
||||
short metaData = 0;
|
||||
if (id.matches("^\\d+[:+',;.]\\d+$"))
|
||||
if (idMatch.matcher(id).matches())
|
||||
{
|
||||
itemid = Integer.parseInt(id.split("[:+',;.]")[0]);
|
||||
metaData = Short.parseShort(id.split("[:+',;.]")[1]);
|
||||
String[] split = metaSplit.split(id);
|
||||
itemid = Integer.parseInt(split[0]);
|
||||
metaData = Short.parseShort(split[1]);
|
||||
}
|
||||
else if (id.matches("^\\d+$"))
|
||||
else if (number.matcher(id).matches())
|
||||
{
|
||||
itemid = Integer.parseInt(id);
|
||||
}
|
||||
else if (id.matches("^[^:+',;.]+[:+',;.]\\d+$"))
|
||||
else if (conjoined.matcher(id).matches())
|
||||
{
|
||||
itemname = id.split("[:+',;.]")[0].toLowerCase(Locale.ENGLISH);
|
||||
metaData = Short.parseShort(id.split("[:+',;.]")[1]);
|
||||
String[] split = metaSplit.split(id);
|
||||
itemname = split[0].toLowerCase(Locale.ENGLISH);
|
||||
metaData = Short.parseShort(split[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package net.ess3.commands;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.permissions.Permissions;
|
||||
@@ -9,6 +10,8 @@ import org.bukkit.command.CommandSender;
|
||||
|
||||
public class Commanddelhome extends EssentialsCommand
|
||||
{
|
||||
private final transient Pattern colon = Pattern.compile(":");
|
||||
|
||||
@Override
|
||||
protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
@@ -22,7 +25,7 @@ public class Commanddelhome extends EssentialsCommand
|
||||
String[] expandedArg;
|
||||
|
||||
//Allowing both formats /sethome khobbits house | /sethome khobbits:house
|
||||
final String[] nameParts = args[0].split(":");
|
||||
final String[] nameParts = colon.split(args[0]);
|
||||
if (nameParts[0].length() != args[0].length())
|
||||
{
|
||||
expandedArg = nameParts;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package net.ess3.commands;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.permissions.Permissions;
|
||||
@@ -13,6 +14,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Commandgive extends EssentialsCommand
|
||||
{
|
||||
private final transient Pattern data = Pattern.compile("[:+',;.]");
|
||||
|
||||
@Override
|
||||
protected void run(final CommandSender sender, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
@@ -45,7 +48,7 @@ public class Commandgive extends EssentialsCommand
|
||||
{
|
||||
for (int i = Util.isInt(args[3]) ? 4 : 3; i < args.length; i++)
|
||||
{
|
||||
final String[] split = args[i].split("[:+',;.]", 2);
|
||||
final String[] split = data.split(args[i], 2);
|
||||
if (split.length < 1)
|
||||
{
|
||||
continue;
|
||||
|
@@ -2,6 +2,7 @@ package net.ess3.commands;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.economy.Trade;
|
||||
@@ -14,6 +15,8 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
public class Commandhome extends EssentialsCommand
|
||||
{
|
||||
private final transient Pattern colon = Pattern.compile(":");
|
||||
|
||||
@Override
|
||||
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
@@ -24,7 +27,7 @@ public class Commandhome extends EssentialsCommand
|
||||
String[] nameParts;
|
||||
if (args.length > 0)
|
||||
{
|
||||
nameParts = args[0].split(":");
|
||||
nameParts = colon.split(args[0]);
|
||||
if (nameParts[0].length() == args[0].length() || !Permissions.HOME_OTHERS.isAuthorized(user))
|
||||
{
|
||||
homeName = nameParts[0];
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package net.ess3.commands;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.permissions.Permissions;
|
||||
@@ -10,6 +11,8 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class Commanditem extends EssentialsCommand
|
||||
{
|
||||
private final transient Pattern data = Pattern.compile("[:+',;.]");
|
||||
|
||||
@Override
|
||||
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
@@ -41,7 +44,7 @@ public class Commanditem extends EssentialsCommand
|
||||
{
|
||||
for (int i = 2; i < args.length; i++)
|
||||
{
|
||||
final String[] split = args[i].split("[:+',;.]", 2);
|
||||
final String[] split = data.split(args[i], 2);
|
||||
if (split.length < 1)
|
||||
{
|
||||
continue;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
package net.ess3.commands;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.permissions.Permissions;
|
||||
@@ -8,13 +9,15 @@ import net.ess3.permissions.Permissions;
|
||||
|
||||
public class Commandsethome extends EssentialsCommand
|
||||
{
|
||||
private final transient Pattern colon = Pattern.compile(":");
|
||||
|
||||
@Override
|
||||
public void run(final IUser user, final String commandLabel, String[] args) throws Exception
|
||||
{
|
||||
if (args.length > 0)
|
||||
{
|
||||
//Allowing both formats /sethome khobbits house | /sethome khobbits:house
|
||||
final String[] nameParts = args[0].split(":");
|
||||
final String[] nameParts = colon.split(args[0]);
|
||||
if (nameParts[0].length() != args[0].length())
|
||||
{
|
||||
args = nameParts;
|
||||
|
@@ -4,6 +4,7 @@ import java.util.HashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.api.ISettings;
|
||||
import net.ess3.api.IUser;
|
||||
@@ -22,6 +23,8 @@ import org.bukkit.material.Colorable;
|
||||
|
||||
public class Commandspawnmob extends EssentialsCommand
|
||||
{
|
||||
private final transient Pattern colon = Pattern.compile(":");
|
||||
|
||||
@Override
|
||||
public void run(final IUser user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
@@ -45,7 +48,7 @@ public class Commandspawnmob extends EssentialsCommand
|
||||
|
||||
|
||||
final String[] mountparts = args[0].split(",");
|
||||
String[] parts = mountparts[0].split(":");
|
||||
String[] parts = colon.split(mountparts[0]);
|
||||
String mobType = parts[0];
|
||||
String mobData = null;
|
||||
if (parts.length == 2)
|
||||
@@ -56,7 +59,7 @@ public class Commandspawnmob extends EssentialsCommand
|
||||
String mountData = null;
|
||||
if (mountparts.length > 1)
|
||||
{
|
||||
parts = mountparts[1].split(":");
|
||||
parts = colon.split(mountparts[1]);
|
||||
mountType = parts[0];
|
||||
if (parts.length == 2)
|
||||
{
|
||||
|
@@ -7,6 +7,7 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
import static net.ess3.I18n._;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.ISettings;
|
||||
@@ -318,12 +319,13 @@ public class EssentialsPlayerListener implements Listener
|
||||
});
|
||||
}
|
||||
}
|
||||
private final Pattern spaceSplit = Pattern.compile(" ");
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
|
||||
public void onPlayerCommandPreprocess(final PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
final IUser user = ess.getUserMap().getUser(event.getPlayer());
|
||||
final String cmd = event.getMessage().toLowerCase(Locale.ENGLISH).split(" ")[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
||||
final String cmd = spaceSplit.split(event.getMessage().toLowerCase(Locale.ENGLISH))[0].replace("/", "").toLowerCase(Locale.ENGLISH);
|
||||
if (ess.getSettings().getData().getCommands().getSocalspy().getSocialspyCommands().contains(cmd))
|
||||
{
|
||||
for (Player player : ess.getServer().getOnlinePlayers())
|
||||
|
@@ -21,6 +21,8 @@ import org.yaml.snakeyaml.nodes.*;
|
||||
public class BukkitConstructor extends Constructor
|
||||
{
|
||||
private final transient Pattern NUMPATTERN = Pattern.compile("\\d+");
|
||||
private final transient Pattern DATAPATTERN = Pattern.compile("[:+',;.]");
|
||||
private final transient Pattern WORD = Pattern.compile("\\W");
|
||||
private final transient IPlugin plugin;
|
||||
|
||||
public BukkitConstructor(final Class clazz, final IPlugin plugin)
|
||||
@@ -59,7 +61,7 @@ public class BukkitConstructor extends Constructor
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final String[] split = val.split("[:+',;.]", 2);
|
||||
final String[] split = DATAPATTERN.split(val, 2);
|
||||
if (split.length == 0)
|
||||
{
|
||||
return null;
|
||||
@@ -92,12 +94,12 @@ public class BukkitConstructor extends Constructor
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final String[] split1 = val.split("\\W");
|
||||
final String[] split1 = WORD.split(val);
|
||||
if (split1.length == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final String[] split2 = split1[0].split("[:+',;.]", 2);
|
||||
final String[] split2 = DATAPATTERN.split(split1[0], 2);
|
||||
if (split2.length == 0)
|
||||
{
|
||||
return null;
|
||||
@@ -131,7 +133,7 @@ public class BukkitConstructor extends Constructor
|
||||
{
|
||||
for (int i = 2; i < split1.length; i++)
|
||||
{
|
||||
final String[] split3 = split1[0].split("[:+',;.]", 2);
|
||||
final String[] split3 = DATAPATTERN.split(split1[0], 2);
|
||||
if (split3.length < 1)
|
||||
{
|
||||
continue;
|
||||
@@ -175,7 +177,7 @@ public class BukkitConstructor extends Constructor
|
||||
{
|
||||
return null;
|
||||
}
|
||||
final String[] split = val.split("[:+',;.]", 2);
|
||||
final String[] split = DATAPATTERN.split(val, 2);
|
||||
if (split.length == 0)
|
||||
{
|
||||
return null;
|
||||
|
@@ -7,6 +7,7 @@ import java.util.LinkedHashSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import net.ess3.api.IEssentials;
|
||||
import net.ess3.api.IUser;
|
||||
import net.ess3.api.IUserMap;
|
||||
@@ -144,11 +145,12 @@ public class UserMap extends StorageObjectMap<IUser> implements IUserMap
|
||||
{
|
||||
return matchUsers(name, false, false, requester);
|
||||
}
|
||||
private final Pattern comma = Pattern.compile(",");
|
||||
|
||||
public Set<IUser> matchUsers(final String name, final boolean includeHidden, final boolean includeOffline, final Player requester)
|
||||
{
|
||||
final String colorlessName = FormatUtil.stripColor(name);
|
||||
final String[] search = colorlessName.split(",");
|
||||
final String[] search = comma.split(colorlessName);
|
||||
final boolean multisearch = search.length > 1;
|
||||
final Set<IUser> result = new LinkedHashSet<IUser>();
|
||||
final String nicknamePrefix = FormatUtil.stripColor(getNickNamePrefix());
|
||||
|
Reference in New Issue
Block a user