Skip to content

Commit 7fc8e2e

Browse files
committed
Format code, better code style
1 parent dfb84c5 commit 7fc8e2e

File tree

5 files changed

+62
-42
lines changed

5 files changed

+62
-42
lines changed

.editorconfig

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = crlf
5+
insert_final_newline = true
6+
charset = utf-8
7+
indent_style = space
8+
intent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.yml]
12+
indent_style = space
13+
indent_size = 2
14+
15+
[pom.xml]
16+
indent_style = space
17+
intent_size = 4

pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34
<artifactId>antiaura</artifactId>
45
<version>0.3-SNAPSHOT</version>

src/main/java/tk/maciekmm/antiaura/AntiAura.java

+10-8
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ public class AntiAura extends JavaPlugin implements Listener {
6262
private boolean isRegistered;
6363
public static final Random RANDOM = new Random();
6464

65+
@Override
6566
public void onEnable() {
6667
this.saveDefaultConfig();
6768
this.getServer().getPluginManager().registerEvents(this, this);
@@ -75,7 +76,7 @@ public void onPacketReceiving(PacketEvent event) {
7576
if (event.getPacketType() == WrapperPlayClientUseEntity.TYPE) {
7677
WrapperPlayClientUseEntity packet = new WrapperPlayClientUseEntity(event.getPacket());
7778
int entID = packet.getTarget();
78-
if (running.containsKey(event.getPlayer().getUniqueId()) && packet.getType().equals(EntityUseAction.ATTACK)) {
79+
if (running.containsKey(event.getPlayer().getUniqueId()) && packet.getType() == EntityUseAction.ATTACK) {
7980
running.get(event.getPlayer().getUniqueId()).markAsKilled(entID);
8081
}
8182
}
@@ -102,37 +103,38 @@ public AuraCheck remove(UUID id) {
102103
return null;
103104
}
104105

106+
@Override
105107
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
106108
if (args.length < 1) {
107109
return false;
108110
}
109-
if(args[0].equalsIgnoreCase("reload")) {
111+
if (args[0].equalsIgnoreCase("reload")) {
110112
this.reloadConfig();
111113
sender.sendMessage(ChatColor.GREEN + "AntiAura config successfully reloaded");
112114
return true;
113115
}
114116

115117
@SuppressWarnings("deprecation")
116118
List<Player> playerList = Bukkit.matchPlayer(args[0]);
117-
Player player = null;
118-
if(playerList.size() == 0) {
119+
Player player;
120+
if (playerList.isEmpty()) {
119121
sender.sendMessage(ChatColor.RED + "Player is not online.");
120122
return true;
121-
} else if(playerList.size() == 1) {
123+
} else if (playerList.size() == 1) {
122124
player = playerList.get(0);
123125
} else {
124126
StringBuilder stringBuilder = new StringBuilder();
125127
stringBuilder.append("[\"\",{\"text\":\"What player do you mean? (click one)\\n\",\"color\":\"green\"},");
126-
for(Player p : playerList) {
127-
stringBuilder.append("{\"text\":\"" + p.getName() + ", \",\"color\":\"blue\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/auracheck " + p.getName() + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"" + p.getName() + "\",\"color\":\"dark_purple\"}]}}},");
128+
for (Player p : playerList) {
129+
stringBuilder.append("{\"text\":\"").append(p.getName()).append(", \",\"color\":\"blue\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/auracheck ").append(p.getName()).append("\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":{\"text\":\"\",\"extra\":[{\"text\":\"").append(p.getName()).append("\",\"color\":\"dark_purple\"}]}}},");
128130
}
129131
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
130132
stringBuilder.append("]");
131133
String json = stringBuilder.toString();
132134
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CHAT);
133135
packet.getChatComponents().write(0, WrappedChatComponent.fromJson(json));
134136
try {
135-
ProtocolLibrary.getProtocolManager().sendServerPacket((Player)sender, packet);
137+
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) sender, packet);
136138
} catch (InvocationTargetException e) {
137139
}
138140
return true;

src/main/java/tk/maciekmm/antiaura/AuraCheck.java

+31-31
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
public class AuraCheck {
4444
private final AntiAura plugin;
45-
private HashMap<Integer, Boolean> entitiesSpawned = new HashMap<>();
45+
private Map<Integer, Boolean> entitiesSpawned = new HashMap<>();
4646
private CommandSender invoker;
4747
private Player checked;
4848
private long started;
@@ -54,37 +54,37 @@ public AuraCheck(AntiAura plugin, Player checked) {
5454
this.checked = checked;
5555
}
5656

57-
public void invoke(CommandSender player,final Callback callback) {
57+
public void invoke(CommandSender player, final Callback callback) {
5858
this.invoker = player;
5959
this.started = System.currentTimeMillis();
60-
60+
6161
int numPlayers = plugin.getConfig().getInt("amountOfFakePlayers");
6262
for (int i = 1; i <= numPlayers; i++) {
6363
int degrees = 360 / (numPlayers - 1) * i;
6464
double radians = Math.toRadians(degrees);
6565
WrapperPlayServerNamedEntitySpawn spawnWrapper;
66-
if(i == 1) {
66+
if (i == 1) {
6767
spawnWrapper = getSpawnWrapper(this.checked.getLocation().add(0, 2, 0).toVector(), plugin);
6868
} else {
69-
spawnWrapper = getSpawnWrapper(this.checked.getLocation().add(2 * Math.cos(radians) ,0.2, 2 * Math.sin(radians)).toVector(), plugin);
69+
spawnWrapper = getSpawnWrapper(this.checked.getLocation().add(2 * Math.cos(radians), 0.2, 2 * Math.sin(radians)).toVector(), plugin);
7070
}
71-
WrapperPlayServerPlayerInfo infoWrapper = getInfoWrapper(spawnWrapper.getPlayerUuid(), PlayerInfoAction.ADD_PLAYER);
71+
WrapperPlayServerPlayerInfo infoWrapper = getInfoWrapper(spawnWrapper.getPlayerUuid(), PlayerInfoAction.ADD_PLAYER);
7272
infoWrapper.sendPacket(this.checked);
7373
spawnWrapper.sendPacket(this.checked);
7474
entitiesSpawned.put(spawnWrapper.getEntityId(), false);
7575
WrapperPlayServerPlayerInfo RemoveinfoWrapper = getInfoWrapper(spawnWrapper.getPlayerUuid(), PlayerInfoAction.REMOVE_PLAYER);
7676
RemoveinfoWrapper.sendPacket(this.checked);
7777
}
78-
78+
7979

8080
Bukkit.getScheduler().runTaskLater(this.plugin, new Runnable() {
8181
@Override
8282
public void run() {
8383
AbstractMap.SimpleEntry<Integer, Integer> result = end();
8484
plugin.remove(checked.getUniqueId());
85-
callback.done(started,finished,result,invoker,checked);
85+
callback.done(started, finished, result, invoker, checked);
8686
}
87-
}, plugin.getConfig().getInt("ticksToKill",10));
87+
}, plugin.getConfig().getInt("ticksToKill", 10));
8888
}
8989

9090
public void markAsKilled(Integer val) {
@@ -115,30 +115,30 @@ public AbstractMap.SimpleEntry<Integer, Integer> end() {
115115
}
116116

117117
public static WrapperPlayServerNamedEntitySpawn getSpawnWrapper(Vector loc, AntiAura plugin) {
118-
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
119-
wrapper.setEntityId(AntiAura.RANDOM.nextInt(20000));
120-
wrapper.setPosition(loc);
121-
wrapper.setPlayerUuid(UUID.randomUUID());
122-
wrapper.setYaw(0.0F);
123-
wrapper.setPitch(-45.0F);
124-
WrappedDataWatcher watcher = new WrappedDataWatcher();
125-
watcher.setObject(0, plugin.getConfig().getBoolean("invisibility", false) ? (Byte) (byte) 0x20 : (byte) 0);
126-
watcher.setObject(6, (Float) (float) 0.5);
127-
watcher.setObject(11, (Byte) (byte) 1);
128-
wrapper.setMetadata(watcher);
129-
return wrapper;
118+
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
119+
wrapper.setEntityId(AntiAura.RANDOM.nextInt(20000));
120+
wrapper.setPosition(loc);
121+
wrapper.setPlayerUuid(UUID.randomUUID());
122+
wrapper.setYaw(0.0F);
123+
wrapper.setPitch(-45.0F);
124+
WrappedDataWatcher watcher = new WrappedDataWatcher();
125+
watcher.setObject(0, plugin.getConfig().getBoolean("invisibility", false) ? (byte) 0x20 : (byte) 0);
126+
watcher.setObject(6, 0.5F);
127+
watcher.setObject(11, (byte) 1);
128+
wrapper.setMetadata(watcher);
129+
return wrapper;
130130
}
131-
132-
131+
132+
133133
public static WrapperPlayServerPlayerInfo getInfoWrapper(UUID playeruuid, PlayerInfoAction action) {
134-
WrapperPlayServerPlayerInfo wrapper = new WrapperPlayServerPlayerInfo();
135-
wrapper.setAction(action);
136-
WrappedGameProfile profile = new WrappedGameProfile(playeruuid, NameGenerator.newName());
137-
PlayerInfoData data = new PlayerInfoData(profile, 1, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(NameGenerator.newName()));
138-
List<PlayerInfoData> listdata = new ArrayList<PlayerInfoData>();
139-
listdata.add(data);
140-
wrapper.setData(listdata);
141-
return wrapper;
134+
WrapperPlayServerPlayerInfo wrapper = new WrapperPlayServerPlayerInfo();
135+
wrapper.setAction(action);
136+
WrappedGameProfile profile = new WrappedGameProfile(playeruuid, NameGenerator.newName());
137+
PlayerInfoData data = new PlayerInfoData(profile, 1, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(NameGenerator.newName()));
138+
List<PlayerInfoData> listdata = new ArrayList<>();
139+
listdata.add(data);
140+
wrapper.setData(listdata);
141+
return wrapper;
142142
}
143143

144144
public static WrapperPlayServerEntityDestroy kill(int entity) {

src/main/java/tk/maciekmm/antiaura/NameGenerator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public static String newName() {
2323
}
2424

2525
private static String getRandomLetter() {
26-
return ((Alphabet) letters.get(rand.nextInt(letters.size()))).name();
26+
return letters.get(rand.nextInt(letters.size())).name();
2727
}
2828

2929
private static enum Alphabet {
3030
a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
3131
}
32-
}
32+
}

0 commit comments

Comments
 (0)