Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Efficiency and better use of API #916

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,13 +505,13 @@ public Level remove(Object key) {
String[] opts = (this.getConfig("worlds." + name + ".generator", Generator.getGenerator("default").getSimpleName())).split(":");
Class<? extends Generator> generator = Generator.getGenerator(opts[0]);
if (opts.length > 1) {
String preset = "";
StringBuilder preset = new StringBuilder();
for (int i = 1; i < opts.length; i++) {
preset += opts[i] + ":";
preset.append(opts[i]).append(":");
}
preset = preset.substring(0, preset.length() - 1);
preset = new StringBuilder(preset.substring(0, preset.length() - 1));

options.put("preset", preset);
options.put("preset", preset.toString());
}

this.generateLevel(name, seed, generator, options);
Expand All @@ -530,7 +530,7 @@ public Level remove(Object key) {
long seed;
String seedString = String.valueOf(this.getProperty("level-seed", System.currentTimeMillis()));
try {
seed = Long.valueOf(seedString);
seed = Long.parseLong(seedString);
} catch (NumberFormatException e) {
seed = seedString.hashCode();
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/cn/nukkit/block/BlockRailDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ protected void updateState() {
getFloorZ() + 0.875D))) {
if (entity instanceof EntityMinecartAbstract) {
isPowered = true;
break;
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/cn/nukkit/blockentity/BlockEntityPistonArm.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ protected void initBlockEntity() {

private void pushEntities() {
float lastProgress = this.getExtendedProgress(this.lastProgress);
double x = (double) (lastProgress * (float) this.facing.getXOffset());
double y = (double) (lastProgress * (float) this.facing.getYOffset());
double z = (double) (lastProgress * (float) this.facing.getZOffset());
double x = lastProgress * (float) this.facing.getXOffset();
double y = lastProgress * (float) this.facing.getYOffset();
double z = lastProgress * (float) this.facing.getZOffset();
AxisAlignedBB bb = new SimpleAxisAlignedBB(x, y, z, x + 1.0D, y + 1.0D, z + 1.0D);
Entity[] entities = this.level.getCollidingEntities(bb);
if (entities.length != 0) {
Expand Down Expand Up @@ -98,4 +98,4 @@ public void saveNBT() {
public CompoundTag getSpawnCompound() {
return (new CompoundTag()).putString("id", "PistonArm").putInt("x", (int) this.x).putInt("y", (int) this.y).putInt("z", (int) this.z);
}
}
}
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/command/FormattedCommandAlias.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private String buildCommand(String formatString, String[] args) {
throw new IllegalArgumentException("Invalid replacement token");
}

int position = Integer.valueOf(formatString.substring(argStart, index));
int position = Integer.parseInt(formatString.substring(argStart, index));

// Arguments are not 0 indexed
if (position == 0) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/cn/nukkit/command/SimpleCommandMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -300,24 +300,24 @@ public void registerServerAliases() {
}
List<String> targets = new ArrayList<>();

String bad = "";
StringBuilder bad = new StringBuilder();

for (String commandString : commandStrings) {
String[] args = commandString.split(" ");
Command command = this.getCommand(args[0]);

if (command == null) {
if (bad.length() > 0) {
bad += ", ";
bad.append(", ");
}
bad += commandString;
bad.append(commandString);
} else {
targets.add(commandString);
}
}

if (bad.length() > 0) {
this.server.getLogger().warning(this.server.getLanguage().translateString("nukkit.command.alias.notFound", new String[]{alias, bad}));
this.server.getLogger().warning(this.server.getLanguage().translateString("nukkit.command.alias.notFound", new String[]{alias, bad.toString()}));
continue;
}

Expand All @@ -328,4 +328,4 @@ public void registerServerAliases() {
}
}
}
}
}
10 changes: 5 additions & 5 deletions src/main/java/cn/nukkit/command/defaults/BanCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
}

String name = args[0];
String reason = "";
StringBuilder reason = new StringBuilder();
for (int i = 1; i < args.length; i++) {
reason += args[i] + " ";
reason.append(args[i]).append(" ");
}

if (reason.length() > 0) {
reason = reason.substring(0, reason.length() - 1);
reason = new StringBuilder(reason.substring(0, reason.length() - 1));
}

sender.getServer().getNameBans().addBan(name, reason, null, sender.getName());
sender.getServer().getNameBans().addBan(name, reason.toString(), null, sender.getName());

Player player = sender.getServer().getPlayerExact(name);
if (player != null) {
player.kick(PlayerKickEvent.Reason.NAME_BANNED, !reason.isEmpty() ? "Banned by admin. Reason: " + reason : "Banned by admin");
player.kick(PlayerKickEvent.Reason.NAME_BANNED, (reason.length() > 0) ? "Banned by admin. Reason: " + reason : "Banned by admin");
}

Command.broadcastCommandMessage(sender, new TranslationContainer("%commands.ban.success", player != null ? player.getName() : name));
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/cn/nukkit/command/defaults/BanIpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,23 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
}

String value = args[0];
String reason = "";
StringBuilder reason = new StringBuilder();
for (int i = 1; i < args.length; i++) {
reason += args[i] + " ";
reason.append(args[i]).append(" ");
}

if (reason.length() > 0) {
reason = reason.substring(0, reason.length() - 1);
reason = new StringBuilder(reason.substring(0, reason.length() - 1));
}

if (Pattern.matches("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", value)) {
this.processIPBan(value, sender, reason);
this.processIPBan(value, sender, reason.toString());

Command.broadcastCommandMessage(sender, new TranslationContainer("commands.banip.success", value));
} else {
Player player = sender.getServer().getPlayer(value);
if (player != null) {
this.processIPBan(player.getAddress(), sender, reason);
this.processIPBan(player.getAddress(), sender, reason.toString());

Command.broadcastCommandMessage(sender, new TranslationContainer("commands.banip.success.players", player.getAddress(), player.getName()));
} else {
Expand All @@ -79,7 +79,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
}

if (nbt != null && nbt.contains("lastIP") && Pattern.matches("^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", (value = nbt.getString("lastIP")))) {
this.processIPBan(value, sender, reason);
this.processIPBan(value, sender, reason.toString());

Command.broadcastCommandMessage(sender, new TranslationContainer("commands.banip.success", value));
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/command/defaults/EffectCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
int amplification = 0;
if (args.length >= 3) {
try {
duration = Integer.valueOf(args[2]);
duration = Integer.parseInt(args[2]);
} catch (NumberFormatException a) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
Expand All @@ -82,7 +82,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
}
if (args.length >= 4) {
try {
amplification = Integer.valueOf(args[3]);
amplification = Integer.parseInt(args[3]);
} catch (NumberFormatException a) {
sender.sendMessage(new TranslationContainer("commands.generic.usage", this.usageMessage));
return true;
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/cn/nukkit/command/defaults/HelpCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
if (!this.testPermission(sender)) {
return true;
}
String command = "";
StringBuilder command = new StringBuilder();
int pageNumber = 1;
int pageHeight = 5;
if (args.length != 0) {
try {
pageNumber = Integer.valueOf(args[args.length - 1]);
pageNumber = Integer.parseInt(args[args.length - 1]);
if (pageNumber <= 0) {
pageNumber = 1;
}
Expand All @@ -50,18 +50,18 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
args = new String[0];
}*/
for (String arg : args) {
if (!command.equals("")) {
command += " ";
if (!command.toString().equals("")) {
command.append(" ");
}
command += arg;
command.append(arg);
}
} catch (NumberFormatException e) {
pageNumber = 1;
for (String arg : args) {
if (!command.equals("")) {
command += " ";
if (!command.toString().equals("")) {
command.append(" ");
}
command += arg;
command.append(arg);
}
}
}
Expand All @@ -70,7 +70,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
pageHeight = Integer.MAX_VALUE;
}

if (command.equals("")) {
if (command.toString().equals("")) {
Map<String, Command> commands = new TreeMap<>();
for (Command cmd : sender.getServer().getCommandMap().getCommands().values()) {
if (cmd.testPermissionSilent(sender)) {
Expand All @@ -94,26 +94,26 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)

return true;
} else {
Command cmd = sender.getServer().getCommandMap().getCommand(command.toLowerCase());
Command cmd = sender.getServer().getCommandMap().getCommand(command.toString().toLowerCase());
if (cmd != null) {
if (cmd.testPermissionSilent(sender)) {
String message = TextFormat.YELLOW + "--------- " + TextFormat.WHITE + " Help: /" + cmd.getName() + TextFormat.YELLOW + " ---------\n";
message += TextFormat.GOLD + "Description: " + TextFormat.WHITE + cmd.getDescription() + "\n";
String usage = "";
StringBuilder usage = new StringBuilder();
String[] usages = cmd.getUsage().split("\n");
for (String u : usages) {
if (!usage.equals("")) {
usage += "\n" + TextFormat.WHITE;
if (!usage.toString().equals("")) {
usage.append("\n" + TextFormat.WHITE);
}
usage += u;
usage.append(u);
}
message += TextFormat.GOLD + "Usage: " + TextFormat.WHITE + usage + "\n";
sender.sendMessage(message);
return true;
}
}

sender.sendMessage(TextFormat.RED + "No help for " + command.toLowerCase());
sender.sendMessage(TextFormat.RED + "No help for " + command.toString().toLowerCase());
return true;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/cn/nukkit/command/defaults/KickCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)

String name = args[0];

String reason = "";
StringBuilder reason = new StringBuilder();
for (int i = 1; i < args.length; i++) {
reason += args[i] + " ";
reason.append(args[i]).append(" ");
}

if (reason.length() > 0) {
reason = reason.substring(0, reason.length() - 1);
reason = new StringBuilder(reason.substring(0, reason.length() - 1));
}

Player player = sender.getServer().getPlayer(name);
if (player != null) {
player.kick(PlayerKickEvent.Reason.KICKED_BY_ADMIN, reason);
player.kick(PlayerKickEvent.Reason.KICKED_BY_ADMIN, reason.toString());
if (reason.length() >= 1) {
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success.reason", player.getName(), reason)
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success.reason", player.getName(), reason.toString())
);
} else {
Command.broadcastCommandMessage(sender, new TranslationContainer("commands.kick.success", player.getName()));
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/cn/nukkit/command/defaults/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
if (!this.testPermission(sender)) {
return true;
}
String online = "";
StringBuilder online = new StringBuilder();
int onlineCount = 0;
for (Player player : sender.getServer().getOnlinePlayers().values()) {
if (player.isOnline() && (!(sender instanceof Player) || ((Player) sender).canSee(player))) {
online += player.getDisplayName() + ", ";
online.append(player.getDisplayName()).append(", ");
++onlineCount;
}
}

if (online.length() > 0) {
online = online.substring(0, online.length() - 2);
online = new StringBuilder(online.substring(0, online.length() - 2));
}

sender.sendMessage(new TranslationContainer("commands.players.list",
String.valueOf(onlineCount), String.valueOf(sender.getServer().getMaxPlayers())));
sender.sendMessage(online);
sender.sendMessage(online.toString());
return true;
}
}
8 changes: 4 additions & 4 deletions src/main/java/cn/nukkit/command/defaults/MeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
name = sender.getName();
}

String msg = "";
StringBuilder msg = new StringBuilder();
for (String arg : args) {
msg += arg + " ";
msg.append(arg).append(" ");
}

if (msg.length() > 0) {
msg = msg.substring(0, msg.length() - 1);
msg = new StringBuilder(msg.substring(0, msg.length() - 1));
}

sender.getServer().broadcastMessage(new TranslationContainer("chat.type.emote", name, TextFormat.WHITE + msg));
sender.getServer().broadcastMessage(new TranslationContainer("chat.type.emote", name, TextFormat.WHITE + msg.toString()));

return true;
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/cn/nukkit/command/defaults/ParticleCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
int count = 1;
if (args.length > 4) {
try {
double c = Double.valueOf(args[4]);
double c = Double.parseDouble(args[4]);
count = (int) c;
} catch (Exception e) {
//ignore
Expand All @@ -83,7 +83,7 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
int data = -1;
if (args.length > 5) {
try {
double d = Double.valueOf(args[5]);
double d = Double.parseDouble(args[5]);
data = (int) d;
} catch (Exception e) {
//ignore
Expand Down Expand Up @@ -184,17 +184,17 @@ private Particle getParticle(String name, Vector3 pos, int data) {
if (name.startsWith("iconcrack_")) {
String[] d = name.split("_");
if (d.length == 3) {
return new ItemBreakParticle(pos, Item.get(Integer.valueOf(d[1]), Integer.valueOf(d[2])));
return new ItemBreakParticle(pos, Item.get(Integer.parseInt(d[1]), Integer.valueOf(d[2])));
}
} else if (name.startsWith("blockcrack_")) {
String[] d = name.split("_");
if (d.length == 2) {
return new TerrainParticle(pos, Block.get(Integer.valueOf(d[1]) & 0xff, Integer.valueOf(d[1]) >> 12));
return new TerrainParticle(pos, Block.get(Integer.parseInt(d[1]) & 0xff, Integer.parseInt(d[1]) >> 12));
}
} else if (name.startsWith("blockdust_")) {
String[] d = name.split("_");
if (d.length >= 4) {
return new DustParticle(pos, Integer.valueOf(d[1]) & 0xff, Integer.valueOf(d[2]) & 0xff, Integer.valueOf(d[3]) & 0xff, d.length >= 5 ? Integer.valueOf(d[4]) & 0xff : 255);
return new DustParticle(pos, Integer.parseInt(d[1]) & 0xff, Integer.parseInt(d[2]) & 0xff, Integer.parseInt(d[3]) & 0xff, d.length >= 5 ? Integer.parseInt(d[4]) & 0xff : 255);
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/cn/nukkit/command/defaults/PluginsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@ public boolean execute(CommandSender sender, String commandLabel, String[] args)
}

private void sendPluginList(CommandSender sender) {
String list = "";
StringBuilder list = new StringBuilder();
Map<String, Plugin> plugins = sender.getServer().getPluginManager().getPlugins();
for (Plugin plugin : plugins.values()) {
if (list.length() > 0) {
list += TextFormat.WHITE + ", ";
list.append(TextFormat.WHITE + ", ");
}
list += plugin.isEnabled() ? TextFormat.GREEN : TextFormat.RED;
list += plugin.getDescription().getFullName();
list.append(plugin.isEnabled() ? TextFormat.GREEN : TextFormat.RED);
list.append(plugin.getDescription().getFullName());
}

sender.sendMessage(new TranslationContainer("nukkit.command.plugins.success", String.valueOf(plugins.size()), list));
sender.sendMessage(new TranslationContainer("nukkit.command.plugins.success", String.valueOf(plugins.size()), list.toString()));
}
}
Loading