Skip to content

Commit

Permalink
Added target for remove command
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorenzo0111 committed Aug 29, 2024
1 parent 0e756b1 commit ad4f87f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import me.zombie_striker.qav.vehicles.AbstractVehicle;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -37,36 +38,48 @@ public String getName() {
}

@Override
@SuppressWarnings("deprecation")
public void perform(CommandSender sender, String[] args) {
if (!sender.hasPermission(PermissionHandler.PERM_REMOVE_VEHICLE)) {
sender.sendMessage(Main.prefix + MessagesConfig.COMMANDMESSAGES_NO_PERM);
return;
}

if (args.length != 1) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.prefix + "&7 Try to use &6/qav removeVehicle <type>"));
if (args.length == 0) {
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', Main.prefix + "&7 Try to use &6/qav removeVehicle <type> [player]"));
return;
}

OfflinePlayer target = args.length == 2 ? Bukkit.getOfflinePlayer(args[1]) : null;

final List<VehicleEntity> collect = Main.vehicles.stream()
.filter(ve -> ve.getType().getName().equalsIgnoreCase(args[0]))
.filter(ve -> target == null || target.getUniqueId().equals(ve.getOwner()))
.collect(Collectors.toList());

Main.vehicles.removeIf(ve -> ve.getType().getName().equalsIgnoreCase(args[0]));

for (VehicleEntity entity : collect) {
entity.deconstruct(null, "Remove command");
}

Bukkit.getScheduler().runTaskAsynchronously(QualityArmoryVehicles.getPlugin(), () -> {
List<File> files = QualityArmoryVehicles.getUnlockedVehiclesFiles();
for (File file : files) {
if (target == null)
Bukkit.getScheduler().runTaskAsynchronously(QualityArmoryVehicles.getPlugin(), () -> {
List<File> files = QualityArmoryVehicles.getUnlockedVehiclesFiles();
for (File file : files) {
List<UnlockedVehicle> unlockedVehicles = QualityArmoryVehicles.parseUnlockedVehicles(file);
unlockedVehicles.removeIf(unlockedVehicle -> unlockedVehicle.getVehicleType().getName().equalsIgnoreCase(args[0]));

QualityArmoryVehicles.setUnlockedVehicles(file, unlockedVehicles);
}
});
else {
Bukkit.getScheduler().runTaskAsynchronously(QualityArmoryVehicles.getPlugin(), () -> {
File file = QualityArmoryVehicles.getUnlockedVehiclesFile(target);
List<UnlockedVehicle> unlockedVehicles = QualityArmoryVehicles.parseUnlockedVehicles(file);
unlockedVehicles.removeIf(unlockedVehicle -> unlockedVehicle.getVehicleType().getName().equalsIgnoreCase(args[0]));

QualityArmoryVehicles.setUnlockedVehicles(file, unlockedVehicles);
}
});
});
}
}

@Override
Expand Down
15 changes: 6 additions & 9 deletions src/main/java/me/zombie_striker/qav/util/BlockCollisionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class BlockCollisionUtil {
}
}

@SuppressWarnings("deprecation")
public static double getHeight(Block b) {
Material type = getMaterial(b.getLocation());
if (type == null) return 0;
Expand All @@ -53,17 +54,13 @@ public static double getHeight(Block b) {
}

return 0.5;
} catch (Exception ignored) {
modernCheck = false;
}
} catch (Exception | Error ignored) {}
}

if (!modernCheck) {
if (b.getData() == 0)
return 0.5;
if (b.getData() == 1)
return 1;
}
if (b.getData() == 0)
return 0.5;
if (b.getData() == 1)
return 1;
}

if (customBlockHeights.containsKey(type))
Expand Down

0 comments on commit ad4f87f

Please sign in to comment.