Skip to content

Commit

Permalink
Added "/carz claim" to allow the user to claim ownership of a car (if…
Browse files Browse the repository at this point in the history
… unclaimed)

Updated Tab autocompletion and "/carz cmds"
Fixed "/carz details"
  • Loading branch information
A5H73Y committed Apr 14, 2020
1 parent 3db6d38 commit 57a1180
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 38 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Add a whole new level of role-play to any server that uses roads, perfect for ci

```
<dependency>
<groupId>me.A5H73Y</groupId>
<groupId>io.github.a5h73y</groupId>
<artifactId>Carz</artifactId>
<version>7.0</version>
<type>jar</type>
Expand All @@ -54,5 +54,5 @@ repositories {
```

```
compile 'me.A5H73Y:Carz:7.0'
compile 'io.github.a5h73y:Carz:7.0'
```
20 changes: 10 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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>
<groupId>me.A5H73Y</groupId>
<groupId>io.github.a5h73y</groupId>
<artifactId>Carz</artifactId>
<version>7.0</version>
<packaging>jar</packaging>
Expand All @@ -30,20 +30,20 @@
</licenses>

<repositories>
<!-- Spigot API -->
<!-- Spigot API Repo -->
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<!-- Vault Repo -->
<repository>
<id>vault-repo</id>
<url>https://jitpack.io</url>
<url>https://jitpack.io/</url>
</repository>
<!-- bStats Repo -->
<repository>
<id>CodeMC</id>
<url>https://repo.codemc.org/repository/maven-public</url>
<url>https://repo.codemc.org/repository/maven-public/</url>
</repository>
<!-- My Bintray repo -->
<repository>
Expand All @@ -53,28 +53,28 @@
</repositories>

<dependencies>
<!--Spigot API-->
<!-- Spigot API -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Bukkit API-->
<!-- Bukkit API -->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.15.2-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Vault API-->
<!-- Vault API -->
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<!--Bountiful API-->
<!-- Bountiful API -->
<dependency>
<groupId>com.connorlinfoot</groupId>
<artifactId>BountifulAPI</artifactId>
Expand Down Expand Up @@ -142,7 +142,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<version>3.2.2</version>
<configuration>
<artifactSet>
<includes>
Expand All @@ -152,7 +152,7 @@
<relocations>
<relocation>
<pattern>org.bstats</pattern>
<shadedPattern>me.A5H73Y.Carz</shadedPattern>
<shadedPattern>io.github.a5h73y.Carz</shadedPattern>
</relocation>
</relocations>
</configuration>
Expand Down
31 changes: 22 additions & 9 deletions src/main/java/io/github/a5h73y/commands/CarzAutoTabCompleter.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,45 @@ public List<String> onTabComplete(CommandSender sender, Command command, String
return null;
}

Player player = (Player) sender;
List<String> allowedCommands = new ArrayList<>();
List<String> filteredCommands = new ArrayList<>();

if (carz.getFuelController().isFuelEnabled()) {
allowedCommands.add("cmds");
allowedCommands.add("claim");
allowedCommands.add("details");

if (Carz.getInstance().getFuelController().isFuelEnabled()) {
allowedCommands.add("fuel");

if (carz.getConfig().getBoolean(Commands.REFUEL.getConfigPath())) {
allowedCommands.add("refuel");
}
}

if (carz.getConfig().getBoolean(Commands.PURCHASE.getConfigPath())) {
allowedCommands.add("purchase");
if (PermissionUtils.hasStrictPermission(player, Permissions.PURCHASE, false)) {
allowedCommands.add("stash");
allowedCommands.add("cartypes");

if (carz.getConfig().getBoolean(Commands.PURCHASE.getConfigPath())) {
allowedCommands.add("purchase");
}
}

if (carz.getConfig().getBoolean(Commands.UPGRADE.getConfigPath())) {
allowedCommands.add("upgrade");
if (carz.getConfig().getBoolean(Commands.UPGRADE.getConfigPath())
&& PermissionUtils.hasStrictPermission(player, Permissions.UPGRADE, false)) {
allowedCommands.add( "upgrade");
}

if (PermissionUtils.hasStrictPermission((Player) sender, Permissions.ADMIN, false)) {
if (PermissionUtils.hasStrictPermission(player, Permissions.ADMIN, false)) {
allowedCommands.add("addCB");
allowedCommands.add("createtype");
allowedCommands.add("economy");
allowedCommands.add("reload");

if (carz.getConfig().getBoolean(Commands.SPAWN.getConfigPath())) {
allowedCommands.add("spawn");
}

allowedCommands.add("reload");
allowedCommands.add("addCB");
}

for (String allowedCommand : allowedCommands) {
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/io/github/a5h73y/commands/CarzCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import io.github.a5h73y.conversation.CreateCarTypeConversation;
import io.github.a5h73y.enums.Commands;
import io.github.a5h73y.enums.Permissions;
import io.github.a5h73y.enums.VehicleDetailKey;
import io.github.a5h73y.model.Car;
import io.github.a5h73y.other.AbstractPluginReceiver;
import io.github.a5h73y.other.CarzHelp;
Expand All @@ -15,13 +16,16 @@
import io.github.a5h73y.purchases.UpgradePurchase;
import io.github.a5h73y.utility.CarUtils;
import io.github.a5h73y.utility.PermissionUtils;
import io.github.a5h73y.utility.StringUtils;
import io.github.a5h73y.utility.TranslationUtils;
import io.github.a5h73y.utility.ValidationUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Minecart;
import org.bukkit.entity.Player;
import org.bukkit.entity.Vehicle;

import static io.github.a5h73y.controllers.CarController.DEFAULT_CAR;

Expand Down Expand Up @@ -55,6 +59,23 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
carz.getFuelController().displayFuelLevel(player);
break;

case "claim":
if (!player.isInsideVehicle() || !(player.getVehicle() instanceof Minecart)
|| !ValidationUtils.isACarzVehicle((Vehicle) player.getVehicle())) {
TranslationUtils.sendTranslation("Error.NotInCar", player);
return false;
}

if (carz.getItemMetaUtils().has(VehicleDetailKey.VEHICLE_OWNER, player.getVehicle())) {
String owner = carz.getItemMetaUtils().getValue(VehicleDetailKey.VEHICLE_OWNER, player.getVehicle());
player.sendMessage(TranslationUtils.getTranslation("Error.Owned").replace("%PLAYER%", owner));
return false;
}

carz.getItemMetaUtils().setValue(VehicleDetailKey.VEHICLE_OWNER, player.getVehicle(), player.getName());
TranslationUtils.sendTranslation("Car.Claimed", player);
break;

case "spawn":
if (!PluginUtils.commandEnabled(player, Commands.SPAWN)) {
return false;
Expand Down Expand Up @@ -140,11 +161,13 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
return false;
}

player.sendMessage(StringUtils.getStandardHeading("Car Types"));
carz.getCarController().getCarTypes().keySet().forEach(player::sendMessage);
break;

case "details":
if (!carz.getCarController().isDriving(player.getName())) {
if (!player.isInsideVehicle()
|| carz.getCarController().getCar(player.getVehicle().getEntityId()) == null) {
TranslationUtils.sendTranslation("Error.NotInCar", player);
return false;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/io/github/a5h73y/configuration/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ private void setupStrings() {
stringsConfig.addDefault("Car.UpgradeSpeed", "New top speed: %SPEED%");
stringsConfig.addDefault("Car.Key.Display", "&b%PLAYER%&f's key");
stringsConfig.addDefault("Car.Key.Received", "You receive a key.");
stringsConfig.addDefault("Car.Claimed", "You are now the owner of this car.");

stringsConfig.addDefault("Purchase.Confirm.Purchase","&7Enter &a/carz confirm &7to confirm, or &c/carz cancel &7to cancel the purchase.");
stringsConfig.addDefault("Purchase.Confirm.Car","You are about to purchase a &b%TYPE% &7car, costing &b%COST%&7.");
Expand Down
16 changes: 11 additions & 5 deletions src/main/java/io/github/a5h73y/model/Car.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

public class Car {

private int entityId;
private final int entityId;

private CarDetails carDetails;
private final String carType;

private final CarDetails carDetails;

private double maxSpeed;

Expand All @@ -23,9 +25,8 @@ public Car(final int entityId) {
public Car(final int entityId, final String carType) {
this.entityId = entityId;
this.currentSpeed = 0.0;

this.carDetails = Carz.getInstance().getCarController().getCarTypes().get(
carType == null ? CarController.DEFAULT_CAR : carType);
this.carType = carType != null ? carType : CarController.DEFAULT_CAR;
this.carDetails = Carz.getInstance().getCarController().getCarTypes().get(carType);
this.currentFuel = Carz.getInstance().getFuelController().getStartAmount();
this.maxSpeed = this.carDetails.getStartMaxSpeed();
}
Expand Down Expand Up @@ -53,6 +54,7 @@ public void resetSpeed() {
public String toString() {
return StringUtils.getStandardHeading("Car Details") +
"\nentityId = " + entityId +
", \ncarType = " + carType +
", \nmaxSpeed = " + maxSpeed +
", \ncurrentSpeed = " + currentSpeed +
", \ncurrentFuel = " + currentFuel +
Expand All @@ -63,6 +65,10 @@ public int getEntityId() {
return entityId;
}

public String getCarType() {
return carType;
}

public Double getCurrentFuel() {
return currentFuel;
}
Expand Down
31 changes: 21 additions & 10 deletions src/main/java/io/github/a5h73y/other/CarzHelp.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,40 @@ public static void displayCommands(Player player) {
FileConfiguration config = Carz.getInstance().getConfig();
player.sendMessage(StringUtils.getStandardHeading("Carz Commands"));

displayCommandUsage(player, "claim", "Claim an unowned car");
displayCommandUsage(player, "details", "Display the current car's details");

if (Carz.getInstance().getFuelController().isFuelEnabled()) {
displayCommandUsage(player, "fuel", "Display the car's fuel");
displayCommandUsage(player, "fuel", "Display the car's remaining fuel");

if (config.getBoolean(Commands.REFUEL.getConfigPath())) {
displayCommandUsage(player, "refuel", "Refuel your car");
displayCommandUsage(player, "refuel", "Request to refuel your car");
}
}

if (config.getBoolean(Commands.SPAWN.getConfigPath()) && player.isOp()) {
displayCommandUsage(player, "spawn", "Spawn a car at your location");
}
if (PermissionUtils.hasStrictPermission(player, Permissions.PURCHASE, false)) {
if (config.getBoolean(Commands.PURCHASE.getConfigPath())) {
displayCommandUsage(player, "purchase", "Request to purchase a car");
}

if (config.getBoolean(Commands.PURCHASE.getConfigPath())) {
displayCommandUsage(player, "purchase", "Purchase a car");
displayCommandUsage(player, "stash", "Stash your owned car back into your inventory");
displayCommandUsage(player, "stash", "Stash your car back into your inventory");
displayCommandUsage(player, "cartypes", "Displays all the available car types");
}

if (config.getBoolean(Commands.UPGRADE.getConfigPath())) {
if (config.getBoolean(Commands.UPGRADE.getConfigPath())
&& PermissionUtils.hasStrictPermission(player, Permissions.UPGRADE, false)) {
displayCommandUsage(player, "upgrade", "Upgrade your car");
}

if (PermissionUtils.hasStrictPermission(player, Permissions.ADMIN, false)) {
displayCommandUsage(player, "reload", "Reload the config");
if (config.getBoolean(Commands.SPAWN.getConfigPath())) {
displayCommandUsage(player, "spawn", "Receive an un-owned car");
}

displayCommandUsage(player, "addCB", "Add a ClimbBlock to the list");
displayCommandUsage(player, "createtype", "Create a new Car Type");
displayCommandUsage(player, "economy", "View Economy information");
displayCommandUsage(player, "reload", "Reload the config");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static boolean canPurchaseUpgrade(Player player, boolean checkEconomy) {
* @return boolean
*/
public static boolean canPurchaseFuel(Player player) {
return canPurchaseUpgrade(player, true);
return canPurchaseFuel(player, true);
}

/**
Expand Down

0 comments on commit 57a1180

Please sign in to comment.