Skip to content

Commit

Permalink
Remove various code smells.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Apr 16, 2022
1 parent 6c09155 commit 9cccfa0
Show file tree
Hide file tree
Showing 19 changed files with 1,139 additions and 1,209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import world.bentobox.bentobox.api.commands.CompositeCommand;
import world.bentobox.bentobox.api.user.User;
Expand Down Expand Up @@ -115,11 +114,10 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>

// Create suggestions with all challenges that is available for users.
returnList.addAll(this.<ChallengesAddon>getAddon().getChallengesManager().getAllChallengesNames(this.getWorld()).
stream().
filter(challenge -> challenge.startsWith(Utils.getGameMode(this.getWorld()) + "_") ||
challenge.startsWith(Utils.getGameMode(this.getWorld()).toLowerCase() + "_")).
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).
collect(Collectors.toList()));
stream().
filter(challenge -> challenge.startsWith(Utils.getGameMode(this.getWorld()) + "_") ||
challenge.startsWith(Utils.getGameMode(this.getWorld()).toLowerCase() + "_")).
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).toList());
break;
case 4:
// Suggest a number of completions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
Expand Down Expand Up @@ -101,7 +99,7 @@ else if (!args.get(1).isEmpty())
Challenge challenge = this.addon.getChallengesManager().getChallenge(challengeName);
User target = User.getInstance(targetUUID);

if (challenge != null && target != null)
if (challenge != null)
{
if (!this.addon.getChallengesManager().isChallengeComplete(targetUUID, this.getWorld(), challenge))
{
Expand Down Expand Up @@ -174,10 +172,9 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>
case 4 ->
// Create suggestions with all challenges that is available for users.
returnList.addAll(this.addon.getChallengesManager().getAllChallengesNames(this.getWorld()).stream().
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).
collect(Collectors.toList()));
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).toList());
default ->
returnList.addAll(Collections.singletonList("help"));
returnList.add("help");
}

return Optional.of(Util.tabLimit(returnList, lastString));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;

import world.bentobox.bentobox.api.addons.Addon;
import world.bentobox.bentobox.api.commands.CompositeCommand;
Expand Down Expand Up @@ -191,12 +189,11 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>
case 4 -> {
// Create suggestions with all challenges that is available for users.
returnList.addAll(this.addon.getChallengesManager().getAllChallengesNames(this.getWorld()).stream().
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).
collect(Collectors.toList()));
map(challenge -> challenge.substring(Utils.getGameMode(this.getWorld()).length() + 1)).toList());
returnList.add("all");
}
default ->
returnList.addAll(Collections.singletonList("help"));
returnList.add("help");
}

return Optional.of(Util.tabLimit(returnList, lastString));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,18 @@ public boolean isValid()
return false;
}

switch (this.statistic.getType())
return switch (this.statistic.getType())
{
case ITEM -> {
return this.material != null && this.material.isItem();
}
case BLOCK -> {
return this.material != null && this.material.isBlock();
}
case ENTITY -> {
return this.entity != null;
}
}
case ITEM -> this.material != null && this.material.isItem();

case BLOCK -> this.material != null && this.material.isBlock();

case ENTITY -> this.entity != null;

case UNTYPED -> true;

};

return true;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;

import lv.id.bonne.panelutils.PanelUtils;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.localization.TextVariables;
import world.bentobox.bentobox.api.user.User;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ public void reload()
this.savePlayersData();
}

// this.challengeDatabase = new Database<>(addon, Challenge.class);
// this.levelDatabase = new Database<>(addon, ChallengeLevel.class);
// this.playersDatabase = new Database<>(addon, ChallengesPlayerData.class);

this.loadAndValidate();
}

Expand Down Expand Up @@ -434,12 +430,6 @@ public boolean loadLevel(@Nullable ChallengeLevel level,
public void removeFromCache(UUID playerID)
{
// Remove due possible issues with saving... (#246)
// if (!this.settings.isStoreAsIslandData() && this.playerCacheData.containsKey(playerID.toString()))
// {
// // save before remove
// this.savePlayerData(playerID.toString());
// this.playerCacheData.remove(playerID.toString());
// }

this.savePlayerData(playerID.toString());

Expand Down Expand Up @@ -841,8 +831,6 @@ public void save()
{
// Challenges and Levels are saved on modifications only to avoid issues with
// NULL's in data after interrupting server while in saving stage.
// this.saveChallenges();
// this.saveLevels();

this.savePlayersData();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,8 @@ else if (challenge.getEnvironment().size() == 1)
{
// Yes list duplication for complete menu.
List<String> missingPermissions = challenge.getRequirements().getRequiredPermissions().stream().
filter(permission -> target == null || !target.hasPermission(permission)).
sorted().
collect(Collectors.toList());
filter(permission -> target == null || !target.hasPermission(permission)).
sorted().toList();

StringBuilder permissionBuilder = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -582,12 +582,12 @@ private enum Button
// ---------------------------------------------------------------------

/**
* This indicate if Reset Challenges must work as reset all.
* This indicates if Reset Challenges must work as reset all.
*/
private boolean resetAllMode;

/**
* This indicate if wipe button should clear all data, or only challenges.
* This indicates if wipe button should clear all data, or only challenges.
*/
private boolean wipeAll;
}

0 comments on commit 9cccfa0

Please sign in to comment.