Skip to content

Commit

Permalink
Separate permission into two permissions (send and accept)
Browse files Browse the repository at this point in the history
  • Loading branch information
Trophonix committed Aug 19, 2017
1 parent 6497383 commit 7135ec1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.trophonix</groupId>
<artifactId>TradePlus</artifactId>
<version>2.43</version>
<version>2.45</version>

<repositories>
<repository>
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/com/trophonix/tradeplus/TradePlus.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public void onEnable() {
if (!getDataFolder().exists()) {
getDataFolder().mkdirs();
try { configFile.createNewFile(); } catch (IOException ex) { ex.printStackTrace(); }
config.set("permissionnode", "tradeplus.trade");
config.set("permissionrequired", false);
config.set("permissions.required", config.getBoolean("permissionrequired", false));
config.set("permissions.send", config.getString("permissionnode", "tradeplus.send"));
config.set("permissions.accept", "tradeplus.accept");
config.set("requestcooldownseconds", 20);
config.set("allow-trade-in-creative", false);
config.set("blocked.blacklist", Arrays.asList("bedrock", "97:3"));
Expand Down Expand Up @@ -137,7 +138,7 @@ public void onEnable() {
" &c- /trade <player name>%NEWLINE%" +
" &c- /trade deny");
lang.set("noperms", "&4&l(!) &r&4You do not have permission to trade");
lang.set("nopermsreceiver", "&4&l(!) &r&4That player does not have permission to trade");
lang.set("nopermsreceiver", "&4&l(!) &r&4That player does not have permission to accept a trade");
lang.set("tradecomplete", "&6&l(!) &r&6The trade was successful!");
lang.set("forcedtrade", "&6&l(!) &r&6You've been forced into a trade with &e%PLAYER%");
lang.set("denied-them", "&4&l(!) &r&4Your trade request to &c%PLAYER% &4was denied");
Expand Down Expand Up @@ -324,6 +325,14 @@ public void onEnable() {
lang.set("creative", "&4&l(!) &r&4You can't trade in creative mode!");
lang.set("creativethem", "&4&l(!) &r&4That player is in creative mode!");
}

if (configVersion < 2.45) {
config.set("permissions.required", config.getBoolean("permissionrequired", false));
config.set("permissions.send", config.getString("permissionnode", "tradeplus.send"));
config.set("permissions.accept", "tradeplus.accept");
config.set("permissionrequired", null);
config.set("permissionnode", null);
}
}
config.set("configversion", Double.parseDouble(getDescription().getVersion()));
saveConfig();
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/trophonix/tradeplus/commands/TradeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
}
final Player player = (Player)sender;

String permissionNode = pl.getConfig().getString("permissionnode");
if (pl.getConfig().getBoolean("permissionrequired")) {
if (!player.hasPermission(permissionNode)) {
boolean permissionRequired = pl.getConfig().getBoolean("permissions.required", false);
String sendPermission = pl.getConfig().getString("permissions.send");
if (permissionRequired) {
if (!player.hasPermission(sendPermission)) {
MsgUtils.send(player, pl.getLang().getString("noperms").split("%NEWLINE%"));
return true;
}
Expand Down Expand Up @@ -73,7 +74,8 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
MsgUtils.send(player, pl.getLang().getString("tradewithself").split("%NEWLINE%"));
return true;
}
if (pl.getConfig().getBoolean("permissionrequired") && !receiver.hasPermission(permissionNode)) {
String acceptPermission = pl.getConfig().getString("permissions.accept", "tradeplus.accept");
if (permissionRequired && !receiver.hasPermission(acceptPermission)) {
MsgUtils.send(player, pl.getLang().getString("nopermsreceiver").replace("%PLAYER%", receiver.getName()).split("%NEWLINE%"));
return true;
}
Expand Down

0 comments on commit 7135ec1

Please sign in to comment.