Skip to content

Commit

Permalink
Fixed some sonarcloud code bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigerpanzer02 committed Jul 10, 2024
1 parent 59c01f2 commit 9e28a26
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import plugily.projects.minigamesbox.classic.PluginMain;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -36,6 +38,7 @@ public class Cuboid {
private final double xMinCentered, xMaxCentered, yMinCentered, yMaxCentered, zMinCentered, zMaxCentered;
private final World world;


public Cuboid(final Location point1, final Location point2) {
xMin = Math.min(point1.getBlockX(), point2.getBlockX());
xMax = Math.max(point1.getBlockX(), point2.getBlockX());
Expand Down Expand Up @@ -124,10 +127,10 @@ public Location getMaxPoint() {
}

public Location getRandomLocation() {
final Random rand = new Random();
final int x = rand.nextInt(Math.abs(xMax - xMin) + 1) + xMin;
final int y = rand.nextInt(Math.abs(yMax - yMin) + 1) + yMin;
final int z = rand.nextInt(Math.abs(zMax - zMin) + 1) + zMin;
PluginMain plugin = JavaPlugin.getPlugin(PluginMain.class);
final int x = plugin.getRandom().nextInt(Math.abs(xMax - xMin) + 1) + xMin;
final int y = plugin.getRandom().nextInt(Math.abs(yMax - yMin) + 1) + yMin;
final int z = plugin.getRandom().nextInt(Math.abs(zMax - zMin) + 1) + zMin;
return new Location(world, x, y, z);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void takeOneItem(Player player, ItemStack stack) {
* @return serialized number
*/
public int serializeInt(int i) {
return (i % 9) == 0 ? i : (int) ((Math.ceil(i / 9) * 9) + 9);
return (i % 9) == 0 ? i : (int) ((Math.ceil((double) i / 9) * 9) + 9);
}

@SuppressWarnings("deprecation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,52 +29,52 @@ public class MaterialUtils {

private static final Set<Material> WALL_SIGNS = new HashSet<Material>() {
{
add(getMat("WALL_SIGN"));
add(getMat("ACACIA_WALL_SIGN"));
add(getMat("BIRCH_WALL_SIGN"));
add(getMat("DARK_OAK_WALL_SIGN"));
add(getMat("JUNGLE_WALL_SIGN"));
add(getMat("OAK_WALL_SIGN"));
add(getMat("SPRUCE_WALL_SIGN"));
add(getMat("WARPED_WALL_SIGN"));
add(getMat("CRIMSON_WALL_SIGN"));
WALL_SIGNS.add(getMat("WALL_SIGN"));
WALL_SIGNS.add(getMat("ACACIA_WALL_SIGN"));
WALL_SIGNS.add(getMat("BIRCH_WALL_SIGN"));
WALL_SIGNS.add(getMat("DARK_OAK_WALL_SIGN"));
WALL_SIGNS.add(getMat("JUNGLE_WALL_SIGN"));
WALL_SIGNS.add(getMat("OAK_WALL_SIGN"));
WALL_SIGNS.add(getMat("SPRUCE_WALL_SIGN"));
WALL_SIGNS.add(getMat("WARPED_WALL_SIGN"));
WALL_SIGNS.add(getMat("CRIMSON_WALL_SIGN"));
}
};

public static final Set<Material> BASIC_SIGNS = new HashSet<Material>() {
{
add(getMat("SIGN"));
add(getMat("STANDING_SIGN"));
add(getMat("ACACIA_SIGN"));
add(getMat("BIRCH_SIGN"));
add(getMat("DARK_OAK_SIGN"));
add(getMat("JUNGLE_SIGN"));
add(getMat("OAK_SIGN"));
add(getMat("SPRUCE_SIGN"));
add(getMat("WARPED_SIGN"));
add(getMat("CRIMSON_SIGN"));
BASIC_SIGNS.add(getMat("SIGN"));
BASIC_SIGNS.add(getMat("STANDING_SIGN"));
BASIC_SIGNS.add(getMat("ACACIA_SIGN"));
BASIC_SIGNS.add(getMat("BIRCH_SIGN"));
BASIC_SIGNS.add(getMat("DARK_OAK_SIGN"));
BASIC_SIGNS.add(getMat("JUNGLE_SIGN"));
BASIC_SIGNS.add(getMat("OAK_SIGN"));
BASIC_SIGNS.add(getMat("SPRUCE_SIGN"));
BASIC_SIGNS.add(getMat("WARPED_SIGN"));
BASIC_SIGNS.add(getMat("CRIMSON_SIGN"));
}
};

public static final Set<Material> ALL_SIGNS = new HashSet<Material>() {
{
addAll(WALL_SIGNS);
addAll(BASIC_SIGNS);
ALL_SIGNS.addAll(WALL_SIGNS);
ALL_SIGNS.addAll(BASIC_SIGNS);
}
};

public static final Set<Material> DOORS = new HashSet<Material>() {
{
add(getMat("WOODEN_DOOR"));
add(getMat("ACACIA_DOOR"));
add(getMat("BIRCH_DOOR"));
add(getMat("DARK_OAK_DOOR"));
add(getMat("JUNGLE_DOOR"));
add(getMat("SPRUCE_DOOR"));
add(getMat("OAK_DOOR"));
add(getMat("WOOD_DOOR"));
add(getMat("WARPED_DOOR"));
add(getMat("CRIMSON_DOOR"));
DOORS.add(getMat("WOODEN_DOOR"));
DOORS.add(getMat("ACACIA_DOOR"));
DOORS.add(getMat("BIRCH_DOOR"));
DOORS.add(getMat("DARK_OAK_DOOR"));
DOORS.add(getMat("JUNGLE_DOOR"));
DOORS.add(getMat("SPRUCE_DOOR"));
DOORS.add(getMat("OAK_DOOR"));
DOORS.add(getMat("WOOD_DOOR"));
DOORS.add(getMat("WARPED_DOOR"));
DOORS.add(getMat("CRIMSON_DOOR"));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public static boolean saveInventoryToFile(JavaPlugin plugin, Player player) {
invFile.delete();
}


FileConfiguration invConfig = YamlConfiguration.loadConfiguration(invFile);

invConfig.set("ExperienceProgress", player.getExp());
Expand Down Expand Up @@ -148,7 +149,6 @@ public static boolean saveInventoryToFile(JavaPlugin plugin, Player player) {
plugin.getLogger().log(Level.INFO, "Saved inventory of {0}", player.getName());
return true;
} catch(Exception ex) {
ex.printStackTrace();
Bukkit.getConsoleSender().sendMessage("Cannot save inventory of player!");
Bukkit.getConsoleSender().sendMessage("Disable inventory saving option in config.yml or restart the server!");
return false;
Expand Down Expand Up @@ -181,14 +181,12 @@ private static Inventory getInventoryFromFile(JavaPlugin plugin, String uuid) {
try {
inventory.setContents(invContents);
} catch(IllegalArgumentException ex) {
ex.printStackTrace();
Bukkit.getConsoleSender().sendMessage("Cannot get inventory of player! Inventory has more items than the default content size.");
Bukkit.getConsoleSender().sendMessage("Disable inventory saving option in config.yml or restart the server!");
}
file.delete();
return inventory;
} catch(Exception ex) {
ex.printStackTrace();
Bukkit.getConsoleSender().sendMessage("Cannot save inventory of player!");
Bukkit.getConsoleSender().sendMessage("Disable inventory saving option in config.yml or restart the server!");
return Bukkit.createInventory(null, 9);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private void startSubmitting() {
long secondDelay = (long) (1000 * 60 * (Math.random() * 30));
scheduler.schedule(submitTask, initialDelay, TimeUnit.MILLISECONDS);
scheduler.scheduleAtFixedRate(
submitTask, initialDelay + secondDelay, 1000 * 60 * 30, TimeUnit.MILLISECONDS);
submitTask, initialDelay + secondDelay, 1800000, TimeUnit.MILLISECONDS);
}

private void submitData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ public static CompletableFuture<Boolean> teleport(Entity entity, Location locati
try {
return Bukkit.getScheduler().callSyncMethod(plugin, () -> PaperLib.teleportAsync(entity, location)).get();
} catch(InterruptedException | ExecutionException | CancellationException e) {
// ignored
Thread.currentThread().interrupt();
}
} else {
entity.teleport(location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static double round(double value, int places) {
throw new IllegalArgumentException();
}

BigDecimal bd = new BigDecimal(value);
BigDecimal bd = BigDecimal.valueOf(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
Expand Down

0 comments on commit 9e28a26

Please sign in to comment.