Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Luncaaa committed Jul 4, 2024
1 parent 5695127 commit bdeb2c4
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 73 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ With a huge list of features this is the best free among us plugin!

## Dependencies

- [HolographicDisplays](https://dev.bukkit.org/projects/holographic-displays/files) Minimum 3.0.0 **OR** [DecentHolograms](https://www.spigotmc.org/resources/decentholograms-1-8-1-19-4-papi-support-no-dependencies.96927/) Minimum 2.8.6
- [HolographicDisplays](https://dev.bukkit.org/projects/holographic-displays/files) Minimum 3.0.0 **OR** [DecentHolograms](https://www.spigotmc.org/resources/decentholograms-1-8-1-19-4-papi-support-no-dependencies.96927/) Minimum 2.8.8
- [ProtocolLib](https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/) Must be latest dev version.
- [PlayerPoints](https://www.spigotmc.org/resources/playerpoints.80745/) Soft dependency, only needed for cosmetics.
- <span style="color:red">Warning!</span> Using commands such as /say or /tell with the config option "hidePlayersOutSideArena" set to true can kick the players inside the arena. To prevent this, you can use the [NoEncryption](https://github.com/Doclic/NoEncryption) plugin.
Expand Down
15 changes: 11 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id 'com.github.johnrengelman.shadow' version '8.1.1'
}

group 'spigot.gradle.project'
Expand All @@ -24,12 +25,18 @@ dependencies {
compileOnly 'org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT'
compileOnly group: "com.comphenix.protocol", name: "ProtocolLib", version: "5.2.0-SNAPSHOT"
compileOnly 'me.filoghost.holographicdisplays:holographicdisplays-api:3.0.0'
compileOnly 'org.black_ixx:playerpoints:3.2.6'
compileOnly 'me.clip:placeholderapi:2.11.5'
compileOnly 'org.black_ixx:playerpoints:3.2.7'
compileOnly 'me.clip:placeholderapi:2.11.6'
compileOnly 'com.mojang:authlib:2.1.28'
compileOnly 'com.github.decentsoftware-eu:decentholograms:2.8.6'
compileOnly 'me.neznamy:tab-api:4.0.2'
compileOnly 'com.github.decentsoftware-eu:decentholograms:2.8.8'
compileOnly 'com.github.NEZNAMY:TAB-API:4.1.6'
implementation 'commons-io:commons-io:2.16.1'

compileOnly files('libs/VentureChat.jar') // 3.7.1
//compileOnly files('libs/CMI-API.jar') // 9.0.0.0
}

shadowJar {
relocate 'org.apache.commons.io', 'com.nktfh100.AmongUs.commons.io'
minimize()
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
13 changes: 13 additions & 0 deletions src/main/java/com/nktfh100/AmongUs/commands/AdminCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,19 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String

/* ---------------------------------------------------- */

else if (args[0].equalsIgnoreCase("test") && sender instanceof Player player && (sender.hasPermission("amongus.admin.test"))) {
PlayerInfo pInfo = Main.getPlayersManager().getPlayerInfo(player);
if (!pInfo.getIsIngame()) {
player.sendMessage(ChatColor.RED + "You are not in an arena!");
return true;
}
pInfo.getArena()._isTesting = true;
pInfo.getArena().testingPlayer = player;
player.sendMessage(ChatColor.GREEN + "Enabled testing mode!");
}

/* ---------------------------------------------------- */

else if (args[0].equalsIgnoreCase("setup") && sender instanceof Player && (sender.hasPermission("amongus.admin.setup") || sender.hasPermission("amongus.admin"))) {
if (args.length == 1) {
ArenaSetupGui.openArenaSetupSelector((Player) sender);
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/com/nktfh100/AmongUs/info/Arena.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
public class Arena {
private File arenaFile;
private FileConfiguration arenaConfig;
private String name;
private final String name;
private String displayName;
private Integer minPlayers;
private Integer maxPlayers;
Expand Down Expand Up @@ -668,16 +668,14 @@ public void playerJoin(Player player) {
AUArenaPlayerJoin ev = new AUArenaPlayerJoin(this, player);
Bukkit.getPluginManager().callEvent(ev);

if (ev.isCancelled()) {
return;
}
if (ev.isCancelled()) return;

if (this.playersSpawns.size() == 0) {
if (this.playersSpawns.isEmpty()) {
Logger.log(Level.SEVERE, "Arena " + this.getDisplayName() + " has no spawns!");
return;
}

if (this.colors_.size() == 0) {
if (this.colors_.isEmpty()) {
Logger.log(Level.SEVERE, "There are not enough colors!");
Logger.log(Level.SEVERE,
"Number of colors: " + Main.getConfigManager().getAllColors().size() + ", Number of players in '" + this.getDisplayName() + "': " + this.getMaxPlayers());
Expand Down Expand Up @@ -1420,11 +1418,8 @@ public void startGame() {

PacketContainer packet = Packets.UPDATE_DISPLAY_NAME(player.getUniqueId(), player.getName(), pInfo.getCustomName());
for (PlayerInfo pInfo1 : this.getPlayersInfo()) {
if (pInfo != pInfo1) {
Packets.sendPacket(pInfo1.getPlayer(), packet);
}
Packets.sendPacket(pInfo1.getPlayer(), packet);
}
Packets.sendPacket(player, packet);
this.vitalsManager.addPlayer(pInfo);
si++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,11 @@ public void execute(Player player) {
player.closeInventory();
arena.endGame(false, GameEndReasons.RELOAD, GameEndWinners.NOBODY);
Location loc = player.getLocation();
String spawnLoc = loc.getWorld().getName() + "," + (loc.getBlockX() + 0.5) + "," + loc.getBlockY() + ","
String spawnLoc = loc.getWorld().getName() + "," + (loc.getBlockX() + 0.5) + "," + loc.getY() + ","
+ (loc.getBlockZ() + 0.5) + "," + loc.getYaw() + "," + loc.getPitch();
List<String> allSpawns = arena.getArenaConfig().getStringList("spawnpoints");
allSpawns.add(spawnLoc);
arena.addPlayerSpawn(new Location(loc.getWorld(), loc.getBlockX() + 0.5, loc.getBlockY(),
arena.addPlayerSpawn(new Location(loc.getWorld(), loc.getBlockX() + 0.5, loc.getY(),
loc.getBlockZ() + 0.5, loc.getYaw(), loc.getPitch()));
arena.getArenaConfig().set("spawnpoints", allSpawns);
arena.saveConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.wrappers.EnumWrappers;
import com.comphenix.protocol.wrappers.WrappedEnumEntityUseAction;
import com.nktfh100.AmongUs.enums.GameState;
import com.nktfh100.AmongUs.info.DeadBody;
import com.nktfh100.AmongUs.info.FakeArmorStand;
Expand Down Expand Up @@ -74,8 +73,12 @@ public void run() {
victimInfo = Main.getPlayersManager().getPlayerInfo(victim);
}

final WrappedEnumEntityUseAction wrappedAction = event.getPacket().getEnumEntityUseActions().read(0);
final EnumWrappers.EntityUseAction action = wrappedAction.getAction();
final EnumWrappers.EntityUseAction action;
if (Main.getVersion()[0] < 17) {
action = event.getPacket().getEntityUseActions().read(0);
} else {
action = event.getPacket().getEnumEntityUseActions().read(0).getAction();
}

if (action == EnumWrappers.EntityUseAction.ATTACK) {
if ((!attackerInfo.getIsIngame() && victimInfo.getIsIngame()) || (attackerInfo.getIsIngame() && !victimInfo.getIsIngame())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ public void loadArena(String key, YamlConfiguration arenaSC, File file) {
Logger.log(Level.INFO,"World: " + world + " doesn't exists!");
continue;
}
Location loc = new Location(world, Double.valueOf(locs[1]), Double.valueOf(locs[2]),
Location loc = new Location(world, Double.valueOf(locs[1]), Double.valueOf(locs[2]) + 0.25,
Double.valueOf(locs[3]), Double.valueOf(locs[4]).floatValue(),
Double.valueOf(locs[5]).floatValue());
created.addPlayerSpawn(loc);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ public void loadCosmetics() {

YamlConfiguration config = YamlConfiguration.loadConfiguration(configFIle);
try {
this.cosmetics = new HashMap<CosmeticType, HashMap<String, CosmeticItem>>();
for (CosmeticType cosmetic_ : CosmeticType.values()) {
String type = cosmetic_.getName();
ConfigurationSection typeSec = config.getConfigurationSection(type);
this.cosmetics = new HashMap<>();
for (CosmeticType cosmetic : CosmeticType.values()) {
String cosmeticName = cosmetic.getName();
ConfigurationSection typeSec = config.getConfigurationSection(cosmeticName);
if (typeSec == null) {
continue;
}
this.cosmetics.put(CosmeticType.valueOf(type.toUpperCase()), new HashMap<String, CosmeticItem>());
this.defaultCosmetics.put(CosmeticType.valueOf(type.toUpperCase()), config.getString("default_" + type));
this.cosmeticsOrder.put(CosmeticType.valueOf(type.toUpperCase()), new ArrayList<CosmeticItem>());
this.cosmetics.put(cosmetic, new HashMap<>());
this.defaultCosmetics.put(cosmetic, config.getString("default_" + cosmeticName));
this.cosmeticsOrder.put(cosmetic, new ArrayList<>());
for (String itemKey : typeSec.getKeys(false)) {
ConfigurationSection itemSec = typeSec.getConfigurationSection(itemKey);
Material mat = Material.getMaterial(itemSec.getString("material", "BARRIER"));
Expand All @@ -58,8 +58,8 @@ public void loadCosmetics() {
int price = itemSec.getInt("price", 0);
String permission = itemSec.getString("permission", "");
CosmeticItem cosmeticItem = new CosmeticItem(itemKey, mat, displayName, name, slot, lore, lore2, lore3, price, permission);
this.cosmetics.get(CosmeticType.valueOf(type.toUpperCase())).put(itemKey, cosmeticItem);
this.cosmeticsOrder.get(CosmeticType.valueOf(type.toUpperCase())).add(cosmeticItem);
this.cosmetics.get(cosmetic).put(itemKey, cosmeticItem);
this.cosmeticsOrder.get(cosmetic).add(cosmeticItem);
}
}

Expand Down
78 changes: 42 additions & 36 deletions src/main/java/com/nktfh100/AmongUs/managers/VisibilityManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,46 +123,45 @@ private void updateVisionOf(PlayerInfo pInfo) {
// players

for (PlayerInfo pInfo1 : this.arena.getPlayersInfo()) {
if(pInfo1 == null) {
continue;
}
if(pInfo1 == null) continue;

Player player1 = pInfo1.getPlayer();
if (!pInfo1.isGhost() && player1 != player) {
if (!pInfo1.getIsInVent() && !pInfo.getIsInCameras()) {
Location player1Loc = player1.getLocation();
if (pInfo1.getIsInCameras()) {
player1Loc = pInfo1.getPlayerCamLocTemp();
}
// if player sees player1
if (this.arena.getEnableReducedVision()) {
if (Utils.isInsideCircle(player.getLocation(), (double) pInfo.getVision(), player1Loc) == 2) { // if player1 goes outside view range
if (!pInfo.getPlayersHidden().contains(player1)) {
this.hidePlayer(pInfo, pInfo1, true);
}
} else if (pInfo.getPlayersHidden().contains(player1)) { // if player1 goes inside view range
this.showPlayer(pInfo, pInfo1, true);
if (pInfo1.isGhost() || player1 == player) continue;

if (!pInfo1.getIsInVent() && !pInfo.getIsInCameras()) {
Location player1Loc = player1.getLocation();
if (pInfo1.getIsInCameras()) {
player1Loc = pInfo1.getPlayerCamLocTemp();
}
// if player sees player1
if (this.arena.getEnableReducedVision()) {
if (Utils.isInsideCircle(player.getLocation(), (double) pInfo.getVision(), player1Loc) == 2) { // if player1 goes outside view range
if (!pInfo.getPlayersHidden().contains(player1)) {
this.hidePlayer(pInfo, pInfo1, true);
}
} else if (pInfo.getPlayersHidden().contains(player1)) { // if player1 goes inside view range
this.showPlayer(pInfo, pInfo1, true);
}
}
}

// if player1 sees player
if (!pInfo.getIsInVent() && !pInfo1.getIsInCameras()) {
Location playerLoc = player.getLocation();
if (pInfo.getIsInCameras()) {
playerLoc = pInfo.getPlayerCamLocTemp();
}
if (this.arena.getEnableReducedVision()) {
if (Utils.isInsideCircle(player1.getLocation(), (double) pInfo1.getVision(), playerLoc) == 2) {
if (!pInfo1.getPlayersHidden().contains(player)) {
this.hidePlayer(pInfo1, pInfo, true);
}
} else if (pInfo1.getPlayersHidden().contains(player)) {
this.showPlayer(pInfo1, pInfo, true);
// if player1 sees player
if (!pInfo.getIsInVent() && !pInfo1.getIsInCameras()) {
Location playerLoc = player.getLocation();
if (pInfo.getIsInCameras()) {
playerLoc = pInfo.getPlayerCamLocTemp();
}
if (this.arena.getEnableReducedVision()) {
if (Utils.isInsideCircle(player1.getLocation(), (double) pInfo1.getVision(), playerLoc) == 2) {
if (!pInfo1.getPlayersHidden().contains(player)) {
this.hidePlayer(pInfo1, pInfo, true);
}
} else if (pInfo1.getPlayersHidden().contains(player)) {
this.showPlayer(pInfo1, pInfo, true);
}
} else if (!pInfo.getIsInVent() && pInfo1.getIsInCameras() && pInfo1.getPlayersHidden().contains(player) && !pInfo.isGhost()) {
this.showPlayer(pInfo1, pInfo, true);
}
} else if (!pInfo.getIsInVent() && pInfo1.getIsInCameras() && pInfo1.getPlayersHidden().contains(player) && !pInfo.isGhost()) {
this.showPlayer(pInfo1, pInfo, true);
}
}
}
Expand All @@ -185,13 +184,20 @@ public void showPlayer(PlayerInfo pInfoToShowTo, PlayerInfo pInfoToShow, Boolean
}

Player playerToShow = pInfoToShow.getPlayer();
PacketContainer spawnPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
Location loc = playerToShow.getLocation();
PacketContainer spawnPacket;
if (Main.getVersion()[0] > 20 || (Main.getVersion()[0] == 20 && Main.getVersion()[1] >= 2)) {
spawnPacket = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
spawnPacket.getEntityTypeModifier().write(0, EntityType.PLAYER);
spawnPacket.getIntegers().write(5, Packets.toPacketRotation(loc.getYaw())).write(4, Packets.toPacketRotation(loc.getPitch()));

} else {
spawnPacket = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
spawnPacket.getBytes().write(0, Packets.toPackedByte(loc.getYaw())).write(1, Packets.toPackedByte(loc.getPitch()));
}
spawnPacket.getIntegers().write(0, playerToShow.getEntityId());
spawnPacket.getUUIDs().write(0, playerToShow.getUniqueId());
spawnPacket.getEntityTypeModifier().write(0, EntityType.PLAYER);
Location loc = playerToShow.getLocation();
spawnPacket.getDoubles().write(0, loc.getX()).write(1, loc.getY()).write(2, loc.getZ());
spawnPacket.getBytes().write(0, Packets.toPackedByte(loc.getYaw())).write(1, Packets.toPackedByte(loc.getPitch()));
Packets.sendPacket(pInfoToShowTo.getPlayer(), spawnPacket);

// metadata packet
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/com/nktfh100/AmongUs/utils/Packets.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,14 @@
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;

public class Packets {

public static byte toPackedByte(float f) {
return (byte) ((int) (f * 256.0F / 360.0F));
}

public static int toPacketRotation(float f) {
return (int) (f * 256.0F / 360.0F);
}

public static void sendPacket(Player p, PacketContainer packet) {
if (p.isOnline() && packet != null) {
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
Expand Down Expand Up @@ -138,7 +141,7 @@ public static PacketContainer SPAWN_PLAYER(Location loc, int entityId, UUID uuid
packet.getUUIDs().write(0, uuid);
packet.getEntityTypeModifier().write(0, EntityType.PLAYER);
packet.getDoubles().write(0, loc.getX()).write(1, loc.getY()).write(2, loc.getZ());
packet.getBytes().write(0, toPackedByte(loc.getYaw())).write(1, toPackedByte(loc.getPitch()));
packet.getIntegers().write(5, toPacketRotation(loc.getYaw())).write(4, toPacketRotation(loc.getPitch()));
return packet;
}

Expand Down Expand Up @@ -181,7 +184,7 @@ public static PacketContainer ENTITY_EQUIPMENT_HEAD(int entityId, Material mat)

public static PacketContainer DESTROY_ENTITY(int entityId) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
packet.getIntLists().write(0, Collections.singletonList(entityId));
packet.getIntegerArrays().write(0, new int[]{entityId});
return packet;
}

Expand Down Expand Up @@ -228,8 +231,8 @@ public static PacketContainer ARMOR_STAND(Location loc, Integer entityId, UUID u
packet.getDoubles().write(0, loc.getX());
packet.getDoubles().write(1, loc.getY()); // location
packet.getDoubles().write(2, loc.getZ());
packet.getBytes().write(0, (byte) 0); // yaw & pitch ?
packet.getBytes().write(1, (byte) 0);
packet.getIntegers().write(4, 0); // yaw & pitch ?
packet.getIntegers().write(5, 0);

return packet;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/nktfh100/AmongUs/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public static ArrayList<Location> generateHollowCircle(Location loc, int radius,
}

public static boolean hasChangedBlockCoordinates(Location fromLoc, Location toLoc) {
return !(fromLoc.getWorld().equals(toLoc.getWorld()) && fromLoc.getBlockX() == toLoc.getBlockX() && fromLoc.getBlockZ() == toLoc.getBlockZ());
return !Objects.equals(fromLoc.getWorld(), toLoc.getWorld()) || fromLoc.getBlockX() != toLoc.getBlockX() || fromLoc.getBlockZ() != toLoc.getBlockZ();
}

// 0 = inside
Expand Down

0 comments on commit bdeb2c4

Please sign in to comment.