Finish /acceptRequest
This commit is contained in:
parent
fd1e4db3d3
commit
7d452469c4
13 changed files with 82 additions and 2 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -94,6 +94,10 @@ commands:
|
||||||
description: Deposit a banknote
|
description: Deposit a banknote
|
||||||
usage: /depositMoney
|
usage: /depositMoney
|
||||||
permission: grimmsserver.depositMoney
|
permission: grimmsserver.depositMoney
|
||||||
|
acceptRequest:
|
||||||
|
description: Accepts a request.
|
||||||
|
usage: /acceptRequest
|
||||||
|
permission: grimmsserver.acceptRequest
|
||||||
permissions:
|
permissions:
|
||||||
grimmsserver.logSelfStats:
|
grimmsserver.logSelfStats:
|
||||||
description: Allows a player to log their own stats
|
description: Allows a player to log their own stats
|
||||||
|
|
@ -163,4 +167,7 @@ permissions:
|
||||||
default: true
|
default: true
|
||||||
grimmsserver.depositMoney:
|
grimmsserver.depositMoney:
|
||||||
description: Allows a player to deposit a banknote
|
description: Allows a player to deposit a banknote
|
||||||
|
default: true
|
||||||
|
grimmsserver.acceptRequest:
|
||||||
|
description: Allows a player to accept a request
|
||||||
default: true
|
default: true
|
||||||
Binary file not shown.
|
|
@ -0,0 +1,36 @@
|
||||||
|
package org.gsdistance.grimmsServer.Commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.gsdistance.grimmsServer.Constructable.Request;
|
||||||
|
import org.gsdistance.grimmsServer.Data.PerSessionDataStorage;
|
||||||
|
|
||||||
|
public class AcceptRequest implements CommandExecutor {
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
if(args.length == 0){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(!PerSessionDataStorage.dataStore.containsKey("request-" + args[0])){
|
||||||
|
sender.sendMessage("No such request found.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Request request = (Request) PerSessionDataStorage.dataStore.get("request-" + args[0]);
|
||||||
|
if(!request.canAccept((Player) sender)){
|
||||||
|
sender.sendMessage("You cannot accept this request.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(request.acceptRequest((Player) sender)){
|
||||||
|
sender.sendMessage("Successfully accepted request that was for: " + request.forPurpose);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("This command can only be run by a player.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -28,5 +28,6 @@ public class CommandRegistry {
|
||||||
GrimmsServer.instance.getCommand("grimmsServerCommands").setExecutor(new LogGrimmsServerCommands());
|
GrimmsServer.instance.getCommand("grimmsServerCommands").setExecutor(new LogGrimmsServerCommands());
|
||||||
GrimmsServer.instance.getCommand("withdrawMoney").setExecutor(new WithdrawMoney());
|
GrimmsServer.instance.getCommand("withdrawMoney").setExecutor(new WithdrawMoney());
|
||||||
GrimmsServer.instance.getCommand("depositMoney").setExecutor(new DepositMoney());
|
GrimmsServer.instance.getCommand("depositMoney").setExecutor(new DepositMoney());
|
||||||
|
GrimmsServer.instance.getCommand("acceptRequest").setExecutor(new AcceptRequest());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,46 @@
|
||||||
package org.gsdistance.grimmsServer.Constructable;
|
package org.gsdistance.grimmsServer.Constructable;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.security.Timestamp;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
public class Request {
|
public class Request {
|
||||||
private UUID uuid;
|
private UUID uuid;
|
||||||
private Function<?, ?> onAccept;
|
private String forPlayer;
|
||||||
|
public String forPurpose;
|
||||||
|
private Function<Object, ?> onAccept;
|
||||||
private LocalDateTime timestamp;
|
private LocalDateTime timestamp;
|
||||||
|
private Object requestData;
|
||||||
|
|
||||||
public Request(Function<?, ?> onAccept) {
|
public Request(Function<Object, ?> onAccept, Player forPlayer, String forPurpose, Object requestData) {
|
||||||
uuid = UUID.randomUUID();
|
uuid = UUID.randomUUID();
|
||||||
this.onAccept = onAccept;
|
this.onAccept = onAccept;
|
||||||
|
this.forPlayer = forPlayer.getName();
|
||||||
|
this.forPurpose = forPurpose;
|
||||||
|
this.requestData = requestData;
|
||||||
this.timestamp = LocalDateTime.now();
|
this.timestamp = LocalDateTime.now();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean canAccept(Player player){
|
||||||
|
if(player.getName().equalsIgnoreCase(forPlayer)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean acceptRequest(Player player){
|
||||||
|
if(canAccept(player)){
|
||||||
|
onAccept.apply(requestData);
|
||||||
|
onAccept = (Object object) -> object;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getTimestamp() {
|
||||||
|
return timestamp;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -94,6 +94,10 @@ commands:
|
||||||
description: Deposit a banknote
|
description: Deposit a banknote
|
||||||
usage: /depositMoney
|
usage: /depositMoney
|
||||||
permission: grimmsserver.depositMoney
|
permission: grimmsserver.depositMoney
|
||||||
|
acceptRequest:
|
||||||
|
description: Accepts a request.
|
||||||
|
usage: /acceptRequest
|
||||||
|
permission: grimmsserver.acceptRequest
|
||||||
permissions:
|
permissions:
|
||||||
grimmsserver.logSelfStats:
|
grimmsserver.logSelfStats:
|
||||||
description: Allows a player to log their own stats
|
description: Allows a player to log their own stats
|
||||||
|
|
@ -163,4 +167,7 @@ permissions:
|
||||||
default: true
|
default: true
|
||||||
grimmsserver.depositMoney:
|
grimmsserver.depositMoney:
|
||||||
description: Allows a player to deposit a banknote
|
description: Allows a player to deposit a banknote
|
||||||
|
default: true
|
||||||
|
grimmsserver.acceptRequest:
|
||||||
|
description: Allows a player to accept a request
|
||||||
default: true
|
default: true
|
||||||
Loading…
Add table
Add a link
Reference in a new issue