From db9ad0bcd3f31ee7ad29dcba99469872c5143dbe Mon Sep 17 00:00:00 2001 From: bowser0000 Date: Tue, 1 Dec 2020 20:03:14 -0500 Subject: Fix warnings Eclipse didn't tell me about Also rename TheMod.java to DankersSkyblockMod.java --- src/main/java/me/Danker/handlers/APIHandler.java | 71 ++++++++----------- .../java/me/Danker/handlers/ConfigHandler.java | 79 ++++++++++------------ .../java/me/Danker/handlers/PacketHandler.java | 6 +- .../java/me/Danker/handlers/ScoreboardHandler.java | 15 ++-- src/main/java/me/Danker/handlers/TextRenderer.java | 5 +- 5 files changed, 75 insertions(+), 101 deletions(-) (limited to 'src/main/java/me/Danker/handlers') diff --git a/src/main/java/me/Danker/handlers/APIHandler.java b/src/main/java/me/Danker/handlers/APIHandler.java index c96aa50..c9460fe 100644 --- a/src/main/java/me/Danker/handlers/APIHandler.java +++ b/src/main/java/me/Danker/handlers/APIHandler.java @@ -1,24 +1,22 @@ package me.Danker.handlers; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Scanner; - import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; - -import me.Danker.TheMod; +import me.Danker.DankersSkyblockMod; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ChatComponentText; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.Scanner; + public class APIHandler { public static JsonObject getResponse(String urlString) { EntityPlayer player = Minecraft.getMinecraft().thePlayer; @@ -31,7 +29,7 @@ public class APIHandler { if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String input; - StringBuffer response = new StringBuffer(); + StringBuilder response = new StringBuilder(); while ((input = in.readLine()) != null) { response.append(input); @@ -39,9 +37,8 @@ public class APIHandler { in.close(); Gson gson = new Gson(); - JsonObject object = gson.fromJson(response.toString(), JsonObject.class); - - return object; + + return gson.fromJson(response.toString(), JsonObject.class); } else { if (urlString.startsWith("https://api.hypixel.net/")) { InputStream errorStream = conn.getErrorStream(); @@ -50,23 +47,19 @@ public class APIHandler { String error = scanner.next(); Gson gson = new Gson(); - JsonObject object = gson.fromJson(error, JsonObject.class); - return object; + return gson.fromJson(error, JsonObject.class); } } else if (urlString.startsWith("https://api.mojang.com/users/profiles/minecraft/") && conn.getResponseCode() == 204) { - player.addChatMessage(new ChatComponentText(TheMod.ERROR_COLOUR + "Failed with reason: Player does not exist.")); + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "Failed with reason: Player does not exist.")); } else { - player.addChatMessage(new ChatComponentText(TheMod.ERROR_COLOUR + "Request failed. HTTP Error Code: " + conn.getResponseCode())); + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "Request failed. HTTP Error Code: " + conn.getResponseCode())); } } - } catch (MalformedURLException ex) { - player.addChatMessage(new ChatComponentText(TheMod.ERROR_COLOUR + "An error has occured. See logs for more details.")); - System.err.println(ex); } catch (IOException ex) { - player.addChatMessage(new ChatComponentText(TheMod.ERROR_COLOUR + "An error has occured. See logs for more details.")); - System.err.println(ex); + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "An error has occured. See logs for more details.")); + ex.printStackTrace(); } - + return new JsonObject(); } @@ -82,7 +75,7 @@ public class APIHandler { if (conn.getResponseCode() == HttpURLConnection.HTTP_OK) { BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); String input; - StringBuffer response = new StringBuffer(); + StringBuilder response = new StringBuilder(); while ((input = in.readLine()) != null) { response.append(input); @@ -90,33 +83,25 @@ public class APIHandler { in.close(); Gson gson = new Gson(); - JsonArray array = gson.fromJson(response.toString(), JsonArray.class); - - return array; + + return gson.fromJson(response.toString(), JsonArray.class); } else { - player.addChatMessage(new ChatComponentText(TheMod.ERROR_COLOUR + "Request failed. HTTP Error Code: " + conn.getResponseCode())); + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "Request failed. HTTP Error Code: " + conn.getResponseCode())); } - } catch (MalformedURLException ex) { - player.addChatMessage(new ChatComponentText(TheMod.ERROR_COLOUR + "An error has occured. See logs for more details.")); - System.err.println(ex); } catch (IOException ex) { - player.addChatMessage(new ChatComponentText(TheMod.ERROR_COLOUR + "An error has occured. See logs for more details.")); - System.err.println(ex); + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "An error has occured. See logs for more details.")); + ex.printStackTrace(); } - + return new JsonArray(); } public static String getUUID(String username) { - Gson gson = new Gson(); - JsonObject uuidResponse = getResponse("https://api.mojang.com/users/profiles/minecraft/" + username); - String UUID = uuidResponse.get("id").getAsString(); - return UUID; + return uuidResponse.get("id").getAsString(); } public static String getLatestProfileID(String UUID, String key) { - Gson gson = new Gson(); EntityPlayer player = Minecraft.getMinecraft().thePlayer; // Get profiles @@ -125,11 +110,11 @@ public class APIHandler { JsonObject profilesResponse = getResponse("https://api.hypixel.net/skyblock/profiles?uuid=" + UUID + "&key=" + key); if (!profilesResponse.get("success").getAsBoolean()) { String reason = profilesResponse.get("cause").getAsString(); - player.addChatMessage(new ChatComponentText(TheMod.ERROR_COLOUR + "Failed with reason: " + reason)); + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "Failed with reason: " + reason)); return null; } if (profilesResponse.get("profiles").isJsonNull()) { - player.addChatMessage(new ChatComponentText(TheMod.ERROR_COLOUR + "This player doesn't appear to have played SkyBlock.")); + player.addChatMessage(new ChatComponentText(DankersSkyblockMod.ERROR_COLOUR + "This player doesn't appear to have played SkyBlock.")); return null; } diff --git a/src/main/java/me/Danker/handlers/ConfigHandler.java b/src/main/java/me/Danker/handlers/ConfigHandler.java index 87b3423..b8fb927 100644 --- a/src/main/java/me/Danker/handlers/ConfigHandler.java +++ b/src/main/java/me/Danker/handlers/ConfigHandler.java @@ -1,30 +1,25 @@ package me.Danker.handlers; -import java.io.File; - -import me.Danker.TheMod; -import me.Danker.commands.BlockSlayerCommand; -import me.Danker.commands.DisplayCommand; -import me.Danker.commands.LootCommand; -import me.Danker.commands.MoveCommand; -import me.Danker.commands.ScaleCommand; -import me.Danker.commands.ToggleCommand; +import me.Danker.DankersSkyblockMod; +import me.Danker.commands.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.common.config.ConfigCategory; import net.minecraftforge.common.config.Configuration; +import java.io.File; + public class ConfigHandler { public static Configuration config; - private static String file = "config/Danker's Skyblock Mod.cfg"; + private final static String file = "config/Danker's Skyblock Mod.cfg"; public static void init() { config = new Configuration(new File(file)); try { config.load(); } catch (Exception ex) { - System.err.println(ex); + ex.printStackTrace(); } finally { config.save(); } @@ -38,7 +33,7 @@ public class ConfigHandler { return config.get(category, key, 0).getInt(); } } catch (Exception ex) { - System.err.println(ex); + ex.printStackTrace(); } finally { config.save(); } @@ -53,7 +48,7 @@ public class ConfigHandler { return config.get(category, key, 0D).getDouble(); } } catch (Exception ex) { - System.err.println(ex); + ex.printStackTrace(); } finally { config.save(); } @@ -68,7 +63,7 @@ public class ConfigHandler { return config.get(category, key, "").getString(); } } catch (Exception ex) { - System.err.println(ex); + ex.printStackTrace(); } finally { config.save(); } @@ -83,7 +78,7 @@ public class ConfigHandler { return config.get(category, key, false).getBoolean(); } } catch (Exception ex) { - System.err.println(ex); + ex.printStackTrace(); } finally { config.save(); } @@ -94,10 +89,9 @@ public class ConfigHandler { config = new Configuration(new File(file)); try { config.load(); - int set = config.get(category, key, value).getInt(); config.getCategory(category).get(key).set(value); } catch (Exception ex) { - System.err.println(ex); + ex.printStackTrace(); } finally { config.save(); } @@ -107,10 +101,9 @@ public class ConfigHandler { config = new Configuration(new File(file)); try { config.load(); - double set = config.get(category, key, value).getDouble(); config.getCategory(category).get(key).set(value); } catch (Exception ex) { - System.err.println(ex); + ex.printStackTrace(); } finally { config.save(); } @@ -120,10 +113,9 @@ public class ConfigHandler { config = new Configuration(new File(file)); try { config.load(); - String set = config.get(category, key, value).getString(); config.getCategory(category).get(key).set(value); } catch (Exception ex) { - System.err.println(ex); + ex.printStackTrace(); } finally { config.save(); } @@ -133,10 +125,9 @@ public class ConfigHandler { config = new Configuration(new File(file)); try { config.load(); - boolean set = config.get(category, key, value).getBoolean(); config.getCategory(category).get(key).set(value); } catch (Exception ex) { - System.err.println(ex); + ex.printStackTrace(); } finally { config.save(); } @@ -149,7 +140,7 @@ public class ConfigHandler { if (!config.hasCategory(category)) return false; return config.getCategory(category).containsKey(key); } catch (Exception ex) { - System.err.println(ex); + ex.printStackTrace(); } finally { config.save(); } @@ -164,7 +155,7 @@ public class ConfigHandler { config.removeCategory(new ConfigCategory(category)); } } catch (Exception ex) { - System.err.println(ex); + ex.printStackTrace(); } finally { config.save(); } @@ -449,7 +440,7 @@ public class ConfigHandler { String onlySlayer = getString("toggles", "BlockSlayer"); if (!onlySlayer.equals("")) { BlockSlayerCommand.onlySlayerName = onlySlayer.substring(0, onlySlayer.lastIndexOf(" ")); - BlockSlayerCommand.onlySlayerNumber = onlySlayer.substring(onlySlayer.lastIndexOf(" ") + 1, onlySlayer.length()); + BlockSlayerCommand.onlySlayerNumber = onlySlayer.substring(onlySlayer.lastIndexOf(" ") + 1); } // Wolf @@ -614,9 +605,9 @@ public class ConfigHandler { // Misc DisplayCommand.display = getString("misc", "display"); DisplayCommand.auto = getBoolean("misc", "autoDisplay"); - TheMod.SKILL_TIME = getInt("misc", "skill50Time") * 20; - TheMod.cakeTime = getDouble("misc", "cakeTime"); - TheMod.showSkillTracker = getBoolean("misc", "showSkillTracker"); + DankersSkyblockMod.SKILL_TIME = getInt("misc", "skill50Time") * 20; + DankersSkyblockMod.cakeTime = getDouble("misc", "cakeTime"); + DankersSkyblockMod.showSkillTracker = getBoolean("misc", "showSkillTracker"); MoveCommand.coordsXY[0] = getInt("locations", "coordsX"); MoveCommand.coordsXY[1] = getInt("locations", "coordsY"); @@ -641,21 +632,21 @@ public class ConfigHandler { ScaleCommand.cakeTimerScale = getDouble("scales", "cakeTimerScale"); ScaleCommand.skillTrackerScale = getDouble("scales", "skillTrackerScale"); - TheMod.MAIN_COLOUR = getString("colors", "main"); - TheMod.SECONDARY_COLOUR = getString("colors", "secondary"); - TheMod.DELIMITER_COLOUR = getString("colors", "delimiter"); - TheMod.ERROR_COLOUR = getString("colors", "error"); - TheMod.TYPE_COLOUR = getString("colors", "type"); - TheMod.VALUE_COLOUR = getString("colors", "value"); - TheMod.SKILL_AVERAGE_COLOUR = getString("colors", "skillAverage"); - TheMod.ANSWER_COLOUR = getString("colors", "answer"); - TheMod.SKILL_50_COLOUR = getString("colors", "skill50Display"); - TheMod.COORDS_COLOUR = getString("colors", "coordsDisplay"); - TheMod.CAKE_COLOUR = getString("colors", "cakeDisplay"); - TheMod.SKILL_TRACKER_COLOUR = getString("colors", "skillTracker"); - TheMod.TRIVIA_WRONG_ANSWER_COLOUR = getString("colors", "triviaWrongAnswer"); - TheMod.LOWEST_BLAZE_COLOUR = getInt("colors", "blazeLowest"); - TheMod.HIGHEST_BLAZE_COLOUR = getInt("colors", "blazeHighest"); + DankersSkyblockMod.MAIN_COLOUR = getString("colors", "main"); + DankersSkyblockMod.SECONDARY_COLOUR = getString("colors", "secondary"); + DankersSkyblockMod.DELIMITER_COLOUR = getString("colors", "delimiter"); + DankersSkyblockMod.ERROR_COLOUR = getString("colors", "error"); + DankersSkyblockMod.TYPE_COLOUR = getString("colors", "type"); + DankersSkyblockMod.VALUE_COLOUR = getString("colors", "value"); + DankersSkyblockMod.SKILL_AVERAGE_COLOUR = getString("colors", "skillAverage"); + DankersSkyblockMod.ANSWER_COLOUR = getString("colors", "answer"); + DankersSkyblockMod.SKILL_50_COLOUR = getString("colors", "skill50Display"); + DankersSkyblockMod.COORDS_COLOUR = getString("colors", "coordsDisplay"); + DankersSkyblockMod.CAKE_COLOUR = getString("colors", "cakeDisplay"); + DankersSkyblockMod.SKILL_TRACKER_COLOUR = getString("colors", "skillTracker"); + DankersSkyblockMod.TRIVIA_WRONG_ANSWER_COLOUR = getString("colors", "triviaWrongAnswer"); + DankersSkyblockMod.LOWEST_BLAZE_COLOUR = getInt("colors", "blazeLowest"); + DankersSkyblockMod.HIGHEST_BLAZE_COLOUR = getInt("colors", "blazeHighest"); } } diff --git a/src/main/java/me/Danker/handlers/PacketHandler.java b/src/main/java/me/Danker/handlers/PacketHandler.java index 716b27c..da7900a 100644 --- a/src/main/java/me/Danker/handlers/PacketHandler.java +++ b/src/main/java/me/Danker/handlers/PacketHandler.java @@ -1,7 +1,5 @@ package me.Danker.handlers; -import java.lang.reflect.Field; - import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; @@ -18,6 +16,8 @@ import net.minecraft.network.play.client.C02PacketUseEntity; import net.minecraft.network.play.server.S04PacketEntityEquipment; import net.minecraft.util.BlockPos; +import java.lang.reflect.Field; + public class PacketHandler extends ChannelDuplexHandler { // Spirit boots fix @@ -47,7 +47,7 @@ public class PacketHandler extends ChannelDuplexHandler { EntityItemFrame itemFrame = (EntityItemFrame) entityHit; ItemStack item = itemFrame.getDisplayedItem(); if (item != null && item.getItem() == Items.arrow) { - BlockPos blockPos = Utils.getBlockUnderItemFrame(mc.theWorld, itemFrame); + BlockPos blockPos = Utils.getBlockUnderItemFrame(itemFrame); if (mc.theWorld.getBlockState(blockPos).getBlock() == Blocks.sea_lantern) { return; } diff --git a/src/main/java/me/Danker/handlers/ScoreboardHandler.java b/src/main/java/me/Danker/handlers/ScoreboardHandler.java index 92fc844..b81689c 100644 --- a/src/main/java/me/Danker/handlers/ScoreboardHandler.java +++ b/src/main/java/me/Danker/handlers/ScoreboardHandler.java @@ -1,13 +1,7 @@ package me.Danker.handlers; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.stream.Collectors; - import com.google.common.collect.Iterables; import com.google.common.collect.Lists; - import net.minecraft.client.Minecraft; import net.minecraft.scoreboard.Score; import net.minecraft.scoreboard.ScoreObjective; @@ -15,6 +9,11 @@ import net.minecraft.scoreboard.ScorePlayerTeam; import net.minecraft.scoreboard.Scoreboard; import net.minecraft.util.StringUtils; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + public class ScoreboardHandler { public static String cleanSB(String scoreboard) { @@ -39,10 +38,10 @@ public class ScoreboardHandler { if (objective == null) return lines; Collection scores = scoreboard.getSortedScores(objective); - List list = Lists.newArrayList(scores.stream() + List list = scores.stream() .filter(input -> input != null && input.getPlayerName() != null && !input.getPlayerName() .startsWith("#")) - .collect(Collectors.toList())); + .collect(Collectors.toList()); if (list.size() > 15) { scores = Lists.newArrayList(Iterables.skip(list, scores.size() - 15)); diff --git a/src/main/java/me/Danker/handlers/TextRenderer.java b/src/main/java/me/Danker/handlers/TextRenderer.java index 0e965e6..cbf196b 100644 --- a/src/main/java/me/Danker/handlers/TextRenderer.java +++ b/src/main/java/me/Danker/handlers/TextRenderer.java @@ -1,15 +1,14 @@ package me.Danker.handlers; -import org.lwjgl.opengl.GL11; - import me.Danker.commands.ToggleCommand; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.util.StringUtils; +import org.lwjgl.opengl.GL11; public class TextRenderer extends Gui { public TextRenderer(Minecraft mc, String text, int x, int y, double scale) { - double scaleReset = (double) Math.pow(scale, -1); + double scaleReset = Math.pow(scale, -1); GL11.glScaled(scale, scale, scale); y -= mc.fontRendererObj.FONT_HEIGHT; -- cgit