Skip to content

Commit

Permalink
Format code, better code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Janmm14 committed Oct 30, 2015
1 parent dfb84c5 commit 7fc8e2e
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 42 deletions.
17 changes: 17 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
root = true

[*]
end_of_line = crlf
insert_final_newline = true
charset = utf-8
indent_style = space
intent_size = 4
trim_trailing_whitespace = true

[*.yml]
indent_style = space
indent_size = 2

[pom.xml]
indent_style = space
intent_size = 4
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<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">
<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">
<modelVersion>4.0.0</modelVersion>
<artifactId>antiaura</artifactId>
<version>0.3-SNAPSHOT</version>
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/tk/maciekmm/antiaura/AntiAura.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class AntiAura extends JavaPlugin implements Listener {
private boolean isRegistered;
public static final Random RANDOM = new Random();

@Override
public void onEnable() {
this.saveDefaultConfig();
this.getServer().getPluginManager().registerEvents(this, this);
Expand All @@ -75,7 +76,7 @@ public void onPacketReceiving(PacketEvent event) {
if (event.getPacketType() == WrapperPlayClientUseEntity.TYPE) {
WrapperPlayClientUseEntity packet = new WrapperPlayClientUseEntity(event.getPacket());
int entID = packet.getTarget();
if (running.containsKey(event.getPlayer().getUniqueId()) && packet.getType().equals(EntityUseAction.ATTACK)) {
if (running.containsKey(event.getPlayer().getUniqueId()) && packet.getType() == EntityUseAction.ATTACK) {
running.get(event.getPlayer().getUniqueId()).markAsKilled(entID);
}
}
Expand All @@ -102,37 +103,38 @@ public AuraCheck remove(UUID id) {
return null;
}

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (args.length < 1) {
return false;
}
if(args[0].equalsIgnoreCase("reload")) {
if (args[0].equalsIgnoreCase("reload")) {
this.reloadConfig();
sender.sendMessage(ChatColor.GREEN + "AntiAura config successfully reloaded");
return true;
}

@SuppressWarnings("deprecation")
List<Player> playerList = Bukkit.matchPlayer(args[0]);
Player player = null;
if(playerList.size() == 0) {
Player player;
if (playerList.isEmpty()) {
sender.sendMessage(ChatColor.RED + "Player is not online.");
return true;
} else if(playerList.size() == 1) {
} else if (playerList.size() == 1) {
player = playerList.get(0);
} else {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("[\"\",{\"text\":\"What player do you mean? (click one)\\n\",\"color\":\"green\"},");
for(Player p : playerList) {
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\"}]}}},");
for (Player p : playerList) {
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\"}]}}},");
}
stringBuilder.deleteCharAt(stringBuilder.length() - 1);
stringBuilder.append("]");
String json = stringBuilder.toString();
PacketContainer packet = new PacketContainer(PacketType.Play.Server.CHAT);
packet.getChatComponents().write(0, WrappedChatComponent.fromJson(json));
try {
ProtocolLibrary.getProtocolManager().sendServerPacket((Player)sender, packet);
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) sender, packet);
} catch (InvocationTargetException e) {
}
return true;
Expand Down
62 changes: 31 additions & 31 deletions src/main/java/tk/maciekmm/antiaura/AuraCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

public class AuraCheck {
private final AntiAura plugin;
private HashMap<Integer, Boolean> entitiesSpawned = new HashMap<>();
private Map<Integer, Boolean> entitiesSpawned = new HashMap<>();
private CommandSender invoker;
private Player checked;
private long started;
Expand All @@ -54,37 +54,37 @@ public AuraCheck(AntiAura plugin, Player checked) {
this.checked = checked;
}

public void invoke(CommandSender player,final Callback callback) {
public void invoke(CommandSender player, final Callback callback) {
this.invoker = player;
this.started = System.currentTimeMillis();

int numPlayers = plugin.getConfig().getInt("amountOfFakePlayers");
for (int i = 1; i <= numPlayers; i++) {
int degrees = 360 / (numPlayers - 1) * i;
double radians = Math.toRadians(degrees);
WrapperPlayServerNamedEntitySpawn spawnWrapper;
if(i == 1) {
if (i == 1) {
spawnWrapper = getSpawnWrapper(this.checked.getLocation().add(0, 2, 0).toVector(), plugin);
} else {
spawnWrapper = getSpawnWrapper(this.checked.getLocation().add(2 * Math.cos(radians) ,0.2, 2 * Math.sin(radians)).toVector(), plugin);
spawnWrapper = getSpawnWrapper(this.checked.getLocation().add(2 * Math.cos(radians), 0.2, 2 * Math.sin(radians)).toVector(), plugin);
}
WrapperPlayServerPlayerInfo infoWrapper = getInfoWrapper(spawnWrapper.getPlayerUuid(), PlayerInfoAction.ADD_PLAYER);
WrapperPlayServerPlayerInfo infoWrapper = getInfoWrapper(spawnWrapper.getPlayerUuid(), PlayerInfoAction.ADD_PLAYER);
infoWrapper.sendPacket(this.checked);
spawnWrapper.sendPacket(this.checked);
entitiesSpawned.put(spawnWrapper.getEntityId(), false);
WrapperPlayServerPlayerInfo RemoveinfoWrapper = getInfoWrapper(spawnWrapper.getPlayerUuid(), PlayerInfoAction.REMOVE_PLAYER);
RemoveinfoWrapper.sendPacket(this.checked);
}


Bukkit.getScheduler().runTaskLater(this.plugin, new Runnable() {
@Override
public void run() {
AbstractMap.SimpleEntry<Integer, Integer> result = end();
plugin.remove(checked.getUniqueId());
callback.done(started,finished,result,invoker,checked);
callback.done(started, finished, result, invoker, checked);
}
}, plugin.getConfig().getInt("ticksToKill",10));
}, plugin.getConfig().getInt("ticksToKill", 10));
}

public void markAsKilled(Integer val) {
Expand Down Expand Up @@ -115,30 +115,30 @@ public AbstractMap.SimpleEntry<Integer, Integer> end() {
}

public static WrapperPlayServerNamedEntitySpawn getSpawnWrapper(Vector loc, AntiAura plugin) {
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
wrapper.setEntityId(AntiAura.RANDOM.nextInt(20000));
wrapper.setPosition(loc);
wrapper.setPlayerUuid(UUID.randomUUID());
wrapper.setYaw(0.0F);
wrapper.setPitch(-45.0F);
WrappedDataWatcher watcher = new WrappedDataWatcher();
watcher.setObject(0, plugin.getConfig().getBoolean("invisibility", false) ? (Byte) (byte) 0x20 : (byte) 0);
watcher.setObject(6, (Float) (float) 0.5);
watcher.setObject(11, (Byte) (byte) 1);
wrapper.setMetadata(watcher);
return wrapper;
WrapperPlayServerNamedEntitySpawn wrapper = new WrapperPlayServerNamedEntitySpawn();
wrapper.setEntityId(AntiAura.RANDOM.nextInt(20000));
wrapper.setPosition(loc);
wrapper.setPlayerUuid(UUID.randomUUID());
wrapper.setYaw(0.0F);
wrapper.setPitch(-45.0F);
WrappedDataWatcher watcher = new WrappedDataWatcher();
watcher.setObject(0, plugin.getConfig().getBoolean("invisibility", false) ? (byte) 0x20 : (byte) 0);
watcher.setObject(6, 0.5F);
watcher.setObject(11, (byte) 1);
wrapper.setMetadata(watcher);
return wrapper;
}


public static WrapperPlayServerPlayerInfo getInfoWrapper(UUID playeruuid, PlayerInfoAction action) {
WrapperPlayServerPlayerInfo wrapper = new WrapperPlayServerPlayerInfo();
wrapper.setAction(action);
WrappedGameProfile profile = new WrappedGameProfile(playeruuid, NameGenerator.newName());
PlayerInfoData data = new PlayerInfoData(profile, 1, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(NameGenerator.newName()));
List<PlayerInfoData> listdata = new ArrayList<PlayerInfoData>();
listdata.add(data);
wrapper.setData(listdata);
return wrapper;
WrapperPlayServerPlayerInfo wrapper = new WrapperPlayServerPlayerInfo();
wrapper.setAction(action);
WrappedGameProfile profile = new WrappedGameProfile(playeruuid, NameGenerator.newName());
PlayerInfoData data = new PlayerInfoData(profile, 1, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(NameGenerator.newName()));
List<PlayerInfoData> listdata = new ArrayList<>();
listdata.add(data);
wrapper.setData(listdata);
return wrapper;
}

public static WrapperPlayServerEntityDestroy kill(int entity) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/tk/maciekmm/antiaura/NameGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public static String newName() {
}

private static String getRandomLetter() {
return ((Alphabet) letters.get(rand.nextInt(letters.size()))).name();
return letters.get(rand.nextInt(letters.size())).name();
}

private static enum Alphabet {
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;
}
}
}

0 comments on commit 7fc8e2e

Please sign in to comment.