Skip to content

Commit

Permalink
Merge pull request #111 from StenAL/features
Browse files Browse the repository at this point in the history
Many mostly automated code quality fixups
  • Loading branch information
PhilippvK authored Jul 1, 2024
2 parents db5983e + 2ebcf63 commit a42cf4d
Show file tree
Hide file tree
Showing 95 changed files with 549 additions and 637 deletions.
5 changes: 2 additions & 3 deletions client/src/main/java/agolf/Conn.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ public void dataReceived(String var1) {
try {
this.writeData("error-debug\t" + this.gameContainer.gameApplet.method32() + "\t" + var2.toString().trim().replace('\n', '\\') + "\t" + var1.replace('\t', '\\') + "\t" + this.aString2373.replace('\t', '\\') + "\t" + this.aString2372.replace('\t', '\\'));
} catch (Exception var3) {
;
}

this.gameContainer.gameApplet.setEndState((Throwable) var4);
this.gameContainer.gameApplet.setEndState(var4);
this.connection.closeConnection();
}
}
Expand Down Expand Up @@ -75,7 +74,7 @@ protected void disconnect() {
}
}

private void handlePacket(String cmd) throws Exception {
private void handlePacket(String cmd) {
String[] args = Tools.separateString(cmd, "\t");
if (args[0].equals("error")) {
if (args[1].equals("vernotok")) {
Expand Down
27 changes: 17 additions & 10 deletions client/src/main/java/agolf/GameApplet.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,17 @@
import agolf.game.GamePanel;
import agolf.lobby.LobbyPanel;
import com.aapeli.applet.AApplet;
import com.aapeli.client.*;
import com.aapeli.client.AutoPopups;
import com.aapeli.client.BadWordFilter;
import com.aapeli.client.ImageManager;
import com.aapeli.client.Parameters;
import com.aapeli.client.SoundManager;
import com.aapeli.client.TextManager;
import org.moparforia.client.Launcher;

import java.awt.*;
import java.awt.Color;
import java.awt.Font;
import java.awt.Image;

public class GameApplet extends AApplet {

Expand All @@ -20,11 +27,11 @@ public class GameApplet extends AApplet {
public static final Color colourButtonYellow = new Color(224, 224, 144);
public static final Color colourButtonRed = new Color(224, 144, 144);
public static final Color colourButtonBlue = new Color(144, 144, 224);
public static final Font fontSerif26b = new Font("Serif", 1, 26);
public static final Font fontSerif20 = new Font("Serif", 0, 20);
public static final Font fontDialog14b = new Font("Dialog", 1, 14);
public static final Font fontDialog12 = new Font("Dialog", 0, 12);
public static final Font fontDialog11 = new Font("Dialog", 0, 11);
public static final Font fontSerif26b = new Font("Serif", Font.BOLD, 26);
public static final Font fontSerif20 = new Font("Serif", Font.PLAIN, 20);
public static final Font fontDialog14b = new Font("Dialog", Font.BOLD, 14);
public static final Font fontDialog12 = new Font("Dialog", Font.PLAIN, 12);
public static final Font fontDialog11 = new Font("Dialog", Font.PLAIN, 11);
private GameContainer gameContainer;
private int activePanel;
private SynchronizedBool syncUnknownBool;
Expand Down Expand Up @@ -284,12 +291,12 @@ private boolean isValidSite() {
}

private boolean containsDomain(String host, String domain, String[] tld) {
for (int i = 0; i < tld.length; ++i) {
if (host.equals(domain + "." + tld[i])) {
for (String text : tld) {
if (host.equals(domain + "." + text)) {
return true;
}

if (host.endsWith("." + domain + "." + tld[i])) {
if (host.endsWith("." + domain + "." + text)) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/agolf/LobbySelectPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ else if (evtSource == this.buttonDual) {
this.writeData("qmpt");
} else {
if (evtSource == this.buttonQuit) {
this.gameContainer.gameApplet.quit((String) null);
this.gameContainer.gameApplet.quit(null);
}

}
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/agolf/LobbySelectRNOPspammer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void run() {

do {
this.lobbySelectPanel.requestNumberOfPlayers();
Tools.sleep((long) sleepTime);
Tools.sleep(sleepTime);
if (sleepTime < 120000) {
sleepTime += 5000;
}
Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/agolf/SpriteManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public int[] getPixelsFromTileCode(int tileCode) {
int shapeIndex = tileCode / 65536 % 256; // Becomes the SpecialIndex if isNoSpecial==2
int foregroundElementIndex = tileCode / 256 % 256;
int backgroundElementIndex = tileCode % 256;
/**
/*
* element index's
* 0=grass, 1=dirt, 2=mud, 3=ice, 4=speed-n, 5=speed-ne, 6=speed-e, 7=speed-se
* 8=speed-s, 9=speed-sw, 10=speed-w, 11=speed-nw
Expand Down
4 changes: 2 additions & 2 deletions client/src/main/java/agolf/TrackCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public class TrackCollection {

private Hashtable tracks = new Hashtable();
private Hashtable<String, String> tracks = new Hashtable<>();


public void addTrack(String author, String name, String data) {
Expand All @@ -15,6 +15,6 @@ public void addTrack(String author, String name, String data) {
public String getTrack(String author, String name) {
System.out.println("--------------- GET TRACK");
String key = author + "\t" + name;
return (String) this.tracks.get(key);
return this.tracks.get(key);
}
}
12 changes: 10 additions & 2 deletions client/src/main/java/agolf/TrackTestLoginPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@

import com.aapeli.multiuser.UsernameValidator;

import java.awt.*;
import java.awt.event.*;
import java.awt.Button;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

class TrackTestLoginPanel extends Panel implements ActionListener, KeyListener {

Expand Down
6 changes: 2 additions & 4 deletions client/src/main/java/agolf/game/ChatPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import agolf.GameApplet;
import agolf.GameContainer;
import com.aapeli.client.InputTextField;
import com.aapeli.client.UrlLabel;
import com.aapeli.colorgui.ColorButton;
import com.aapeli.multiuser.ChatBase;
import com.aapeli.multiuser.ChatTextArea;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand Down Expand Up @@ -161,7 +159,7 @@ protected void addBroadcastMessage(String message) {

private void create() {
this.setLayout(null);
this.textAreaChat = new ChatTextArea(this.gameContainer.textManager, this.gameContainer.badWordFilter, this.width, this.height - 22, new Font("Dialog", 0, 11));
this.textAreaChat = new ChatTextArea(this.gameContainer.textManager, this.gameContainer.badWordFilter, this.width, this.height - 22, new Font("Dialog", Font.PLAIN, 11));
this.textAreaChat.setLocation(0, 0);
this.textFieldMessage = new InputTextField(this.gameContainer.textManager.getGame("GameChat_TypeHere"), 200, true);
this.textFieldMessage.setBounds(0, this.height - 20, this.width - 70, 20);
Expand Down Expand Up @@ -191,7 +189,7 @@ private void method323() {
}

if (var1 != ChatBase.CIDR_NONE) {
ChatBase.setInputByCIDR(var1, this, this.textFieldMessage, this.buttonSay, (UrlLabel) null, this.gameContainer.textManager, this.gameContainer.params);
ChatBase.setInputByCIDR(var1, this, this.textFieldMessage, this.buttonSay, null, this.gameContainer.textManager, this.gameContainer.params);
}
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/main/java/agolf/game/ConfirmButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class ConfirmButton extends Canvas implements MouseMotionListener, MouseListener {

private static final Font fontDialog12 = new Font("Dialog", 0, 12);
private static final Font fontDialog12 = new Font("Dialog", Font.PLAIN, 12);
private static final Color colourWhite = new Color(192, 192, 192);
private static final Color colourBlack = new Color(0, 0, 0);
private Font font;
Expand Down
14 changes: 7 additions & 7 deletions client/src/main/java/agolf/game/GameBackgroundCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import agolf.GameApplet;
import agolf.GameContainer;

import java.awt.*;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.util.StringTokenizer;

public class GameBackgroundCanvas extends Canvas {
Expand Down Expand Up @@ -244,7 +247,7 @@ private boolean parseMapInstruction(String map) throws Exception {
if(subtknzr.countTokens() != 4) {
return false;
}
/**
/*
* 0 = num of completions
* 1 = num of strokes
* 2 = best num of strokes
Expand Down Expand Up @@ -384,7 +387,7 @@ private boolean parseMapInstruction(String map) throws Exception {
return true;
}

private String expandMap(String mapString) throws Exception {
private String expandMap(String mapString) {
StringBuffer buffer = new StringBuffer(4900);
int length = mapString.length();

Expand All @@ -408,9 +411,7 @@ private String expandMap(String mapString) throws Exception {

char var6 = mapString.charAt(var4);

for (int var7 = 0; var7 < var5; ++var7) {
buffer.append(var6);
}
buffer.append(String.valueOf(var6).repeat(Math.max(0, var5)));
}

return buffer.toString();
Expand Down Expand Up @@ -660,7 +661,6 @@ private void drawMap() {
}
}
} catch (OutOfMemoryError e) {
;
}

this.graphics.drawImage(this.gameContainer.imageManager.createImage(mapPixels, 735, 375), 0, 0, this);
Expand Down
29 changes: 18 additions & 11 deletions client/src/main/java/agolf/game/GameCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import agolf.GameContainer;
import agolf.Seed;
import agolf.SynchronizedBool;

import com.aapeli.client.Parameters;
import com.aapeli.client.StringDraw;
import com.aapeli.tools.Tools;

import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.Vector;
Expand All @@ -21,7 +28,7 @@ public class GameCanvas extends GameBackgroundCanvas implements Runnable, MouseM
private static final Cursor cursorDefault = new Cursor(Cursor.DEFAULT_CURSOR);
private static final Cursor cursorCrosshair = new Cursor(Cursor.CROSSHAIR_CURSOR);
private static final Color colourAimLine = new Color(128, 0, 32);
private static final Font gameFont = new Font("Dialog", 0, 10);
private static final Font gameFont = new Font("Dialog", Font.PLAIN, 10);
private static final Color blackColour = Color.black;
private static final Color whiteColour = Color.white;
private static final Color backgroundColour = new Color(19, 167, 19);
Expand Down Expand Up @@ -785,9 +792,9 @@ protected boolean init(String commandLines, String playerStatuses, int gameId) {

for (int magnetIndex = 0; magnetIndex < magnetVecLen; ++magnetIndex) {
// [ x, y, blockid ]
int[] magnet = (int[]) magnetVec.elementAt(magnetIndex);
double forceTemp2X = (double) (magnet[0] - magnetLoopX);
double forcetemp2Y = (double) (magnet[1] - magnetLoopY);
int[] magnet = magnetVec.elementAt(magnetIndex);
double forceTemp2X = magnet[0] - magnetLoopX;
double forcetemp2Y = magnet[1] - magnetLoopY;
double force = Math.sqrt(forceTemp2X * forceTemp2X + forcetemp2Y * forcetemp2Y);
if (force <= 127.0D) {
double var35 = Math.abs(forceTemp2X) / force;
Expand Down Expand Up @@ -1394,7 +1401,7 @@ private void handleTeleport(int teleportId, int playerId, int x, int y) {
do {
i = startLen - 1;
random = this.rngSeed.next() % (i + 1);
teleportPos = (double[]) this.teleportStarts[teleportId].elementAt(random);
teleportPos = this.teleportStarts[teleportId].elementAt(random);
if (Math.abs(teleportPos[0] - (double) x) >= 15.0D || Math.abs(teleportPos[1] - (double) y) >= 15.0D) {
this.playerX[playerId] = teleportPos[0];
this.playerY[playerId] = teleportPos[1];
Expand Down Expand Up @@ -1429,7 +1436,7 @@ private void handleTeleport(int teleportId, int playerId, int x, int y) {
}

//finally move player to exit position
teleportPos = (double[]) this.teleportExists[var13].elementAt(random);
teleportPos = this.teleportExists[var13].elementAt(random);
this.playerX[playerId] = teleportPos[0];
this.playerY[playerId] = teleportPos[1];
}
Expand Down Expand Up @@ -1666,8 +1673,8 @@ private void drawDashedLine(Graphics var1, int var2, int var3, int var4, int var
int var6 = var4 >= 0 ? var4 : -var4;
int var7 = var5 >= 0 ? var5 : -var5;
int var8 = Math.max(var6, var7) / 10;
double var9 = (double) var2;
double var11 = (double) var3;
double var9 = var2;
double var11 = var3;
double var13 = (double) var4 / ((double) var8 * 2.0D);
double var15 = (double) var5 / ((double) var8 * 2.0D);
var9 += var13;
Expand Down
3 changes: 1 addition & 2 deletions client/src/main/java/agolf/game/GameControlPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.awt.Checkbox;
import java.awt.Graphics;
import java.awt.LayoutManager;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
Expand Down Expand Up @@ -35,7 +34,7 @@ protected GameControlPanel(GameContainer var1, PlayerInfoPanel var2, int var3, i
this.anInt342 = var3;
this.anInt343 = var4;
this.setSize(var3, var4);
this.setLayout((LayoutManager) null);
this.setLayout(null);
this.skipButtonVisible = false;
}

Expand Down
16 changes: 8 additions & 8 deletions client/src/main/java/agolf/game/HackedShot.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public class HackedShot implements Runnable {
private double aDouble2820;
private double[] aDoubleArray2821;
private double[] aDoubleArray2822;
private Vector[] aVectorArray2823;
private Vector[] aVectorArray2824;
private Vector<double[]>[] aVectorArray2823;
private Vector<double[]>[] aVectorArray2824;
private short[][][] aShortArrayArrayArray2825;
private double[] playerX;
private double[] playerY;
Expand Down Expand Up @@ -60,8 +60,8 @@ public HackedShot(int anInt2809,
double aDouble2820,
double[] aDoubleArray2821,
double[] aDoubleArray2822,
Vector[] aVectorArray2823,
Vector[] aVectorArray2824,
Vector<double[]>[] aVectorArray2823,
Vector<double[]>[] aVectorArray2824,
short[][][] aShortArrayArrayArray2825,
double[] playerX,
double[] playerY,
Expand Down Expand Up @@ -106,8 +106,8 @@ public HackedShot(int anInt2809,
this.aSeed_2836 = aSeed_2836.clone();
this.anInt2839 = anInt2839;
this.aBoolean2843 = aBoolean2843;
this.isSolidArrayIThink = Arrays.copyOf(isSolidArrayIThink, isSolidArrayIThink.length);;
this.mapTiles = Arrays.copyOf(mapTiles , mapTiles .length);;
this.isSolidArrayIThink = Arrays.copyOf(isSolidArrayIThink, isSolidArrayIThink.length);
this.mapTiles = Arrays.copyOf(mapTiles , mapTiles .length);


}
Expand Down Expand Up @@ -515,7 +515,7 @@ private void method154(int var1, int var2, int var3, int var4) {
do {
var10 = var7 - 1;
var8 = this.aSeed_2836.next() % (var10 + 1);
var11 = (double[]) this.aVectorArray2823[var1].elementAt(var8);
var11 = this.aVectorArray2823[var1].elementAt(var8);
if (Math.abs(var11[0] - (double) var3) >= 15.0D || Math.abs(var11[1] - (double) var4) >= 15.0D) {
this.playerX[var2] = var11[0];
this.playerY[var2] = var11[1];
Expand Down Expand Up @@ -549,7 +549,7 @@ private void method154(int var1, int var2, int var3, int var4) {
var8 = this.aSeed_2836.next() % (var12 + 1);
}

var11 = (double[]) this.aVectorArray2824[var13].elementAt(var8);
var11 = this.aVectorArray2824[var13].elementAt(var8);
this.playerX[var2] = var11[0];
this.playerY[var2] = var11[1];
}
Expand Down
9 changes: 4 additions & 5 deletions client/src/main/java/agolf/game/TrackInfoPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

class TrackInfoPanel extends Panel implements ActionListener {

private static final Font fontDialog12 = new Font("Dialog", 0, 12);
private static final Font fontDialog14 = new Font("Dialog", 0, 14);
private static final Font fontSerif16 = new Font("Serif", 0, 16);
private static final Font fontDialog11 = new Font("Dialog", 0, 11);
private static final Font fontDialog12 = new Font("Dialog", Font.PLAIN, 12);
private static final Font fontDialog14 = new Font("Dialog", Font.PLAIN, 14);
private static final Font fontSerif16 = new Font("Serif", Font.PLAIN, 16);
private static final Font fontDialog11 = new Font("Dialog", Font.PLAIN, 11);
private static final Color[] voteColours = new Color[]{
new Color(192, 0, 0), new Color(255, 0, 0), new Color(255, 64, 0),
new Color(255, 128, 0), new Color(255, 192, 0), new Color(255, 255, 0),
Expand Down Expand Up @@ -108,7 +108,6 @@ public void update(Graphics g) {

Font font;
for (font = fontSerif16; this.getFontMetrics(font).stringWidth(this.trackName) / 2 > this.width / 4 - xMod; font = new Font(font.getName(), font.getStyle(), font.getSize() - 1)) {
;
}

this.graphics.setFont(font);
Expand Down
Loading

0 comments on commit a42cf4d

Please sign in to comment.