Skip to content

Commit

Permalink
Added 'friend regions' to the '/as me' command
Browse files Browse the repository at this point in the history
And added teleporting to regions you are added as friend (permissions
areashop.teleportfriend and areashop.teleportfriendsign)
  • Loading branch information
NLthijs48 committed Dec 5, 2014
1 parent 83778ff commit 2c1771c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 16 deletions.
9 changes: 7 additions & 2 deletions lang/EN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ teleport-noPermission: "You don't have permission to teleport to your region"
teleport-noPermissionOther: "You don't have permission to teleport to regions you do not own"
teleport-noPermissionSign: "You don't have permission to teleport to the sign of your region"
teleport-noPermissionOtherSign: "You don't have permission to teleport to signs of regions you do not own"
teleport-noPermissionFriend: "You don't have permission to teleport to regions you are added as friend"
teleport-noPermissionFriendSign: "You don't have permission to teleport to the sign of region you are added as friend"
teleport-success: "You teleported to %0%"
teleport-successSign: "You teleported to the sign of %0%"
teleport-noSafe: "No safe position found in region %0%, no spots in region left or maximum tries exceeded (%1%/%2%)"
Expand Down Expand Up @@ -321,8 +323,11 @@ me-noRentRegions: "You have not rented any rent regions"
me-noBuyRegions: "You have not bought any buy regions"
me-rentRegions: "You have rented the following regions:"
me-buyRegions: "You have bought the following regions:"
me-rentLine: "%region% until %until% (%timeleft% left)"
me-buyLine: "%region%"
me-rentLine: "&2&l►&r %region% until %until% &7(%timeleft% left)"
me-buyLine: "&2&l►&r %region%"
me-noFriendRegions: "You have not been added to regions as friend"
me-friendRegions: "You are added as friend to the following regions:"
me-friendLine: "&2&l►&r %region% &7(owner: %player%)"

setowner-help: "/as setowner <player> [region], the region you stand in will be used if not specified"
setowner-noPermission: "You don't have permission to set the owner of a region"
Expand Down
6 changes: 6 additions & 0 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ permissions:
areashop.teleportsignall:
description: Teleport to signs of all regions
default: op
areashop.teleportfriend:
description: Teleport to regions where you are added as friend
default: true
areashop.teleportfriendsign:
description: Teleport to the sign of regions where you are added as friend
default: true
areashop.setteleport:
description: Set the teleport spot for your region
default: true
Expand Down
6 changes: 2 additions & 4 deletions src/nl/evolutioncoding/areashop/AreaShop.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,8 @@ public void run() {
*/
public void configurableMessage(Object target, String key, boolean prefix, Object... params) {
String langString = this.fixColors(languageManager.getLang(key, params));
if(langString == null) {
this.getLogger().info("Something is wrong with the language file, could not find key: " + key);
} else if(langString.equals("")) {
// Do nothing, message is disabled
if(langString == null || langString.equals("")) {
// Do nothing, message is not available or disabled
} else {
if(target instanceof Player) {
if(prefix) {
Expand Down
22 changes: 19 additions & 3 deletions src/nl/evolutioncoding/areashop/commands/MeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import nl.evolutioncoding.areashop.AreaShop;
import nl.evolutioncoding.areashop.regions.BuyRegion;
import nl.evolutioncoding.areashop.regions.GeneralRegion;
import nl.evolutioncoding.areashop.regions.RentRegion;

import org.bukkit.command.Command;
Expand Down Expand Up @@ -62,17 +63,32 @@ public void execute(CommandSender sender, Command command, String[] args) {
} else {
plugin.message(player, "me-rentRegions");
for(RentRegion region : rentRegions) {
plugin.configurableMessage(player, "me-rentLine", false, region);
plugin.messageNoPrefix(player, "me-rentLine", region);
}
}
if(buyRegions.isEmpty()) {
plugin.message(player, "me-noBuyRegions");
} else {
plugin.message(player, "me-buyRegions");
for(BuyRegion region : buyRegions) {
plugin.configurableMessage(player, "me-buyLine", false, region);
plugin.messageNoPrefix(player, "me-buyLine", region);
}
}
}
Set<GeneralRegion> friendRegions = new HashSet<GeneralRegion>();
for(GeneralRegion region : plugin.getFileManager().getRegions()) {
if(region.getFriends().contains(player.getUniqueId())) {
friendRegions.add(region);
}
}
if(friendRegions.isEmpty()) {
plugin.message(player, "me-noFriendRegions");
} else {
plugin.message(player, "me-friendRegions");
for(GeneralRegion region : friendRegions) {
plugin.messageNoPrefix(player, "me-friendLine", region);
}
}

}

@Override
Expand Down
22 changes: 15 additions & 7 deletions src/nl/evolutioncoding/areashop/regions/GeneralRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -1240,6 +1240,7 @@ public void setTeleport(Location location) {
public boolean teleportPlayer(Player player, boolean toSign, boolean checkPermissions) {
int checked = 1;
boolean owner = false;
boolean friend = getFriends().contains(player.getUniqueId());
Location startLocation = null;
ProtectedRegion region = getRegion();
if(isRentRegion()) {
Expand All @@ -1248,25 +1249,32 @@ public boolean teleportPlayer(Player player, boolean toSign, boolean checkPermis
owner = player.getUniqueId().equals(((BuyRegion)this).getBuyer());
}

// Teleport to sign instead if they dont have permission for teleporting to region
if(!toSign && owner && !player.hasPermission("areashop.teleport")
|| !toSign && !owner && !player.hasPermission("areashop.teleportall")) {
toSign = true;
}
if(checkPermissions) {
// Teleport to sign instead if they dont have permission for teleporting to region
if(!toSign && owner && !player.hasPermission("areashop.teleport") && player.hasPermission("areashop.teleportsign")
|| !toSign && !owner && !friend && !player.hasPermission("areashop.teleportall") && player.hasPermission("areashop.teleportsignall")
|| !toSign && !owner && friend && !player.hasPermission("areashop.teleportfriend") && player.hasPermission("areashop.teleportfriendsign")) {
toSign = true;
}
// Check permissions
if(owner && !player.hasPermission("areashop.teleport") && !toSign) {
plugin.message(player, "teleport-noPermission");
return false;
} else if(!owner && !player.hasPermission("areashop.teleportall") && !toSign) {
} else if(!owner && !player.hasPermission("areashop.teleportall") && !toSign && !friend) {
plugin.message(player, "teleport-noPermissionOther");
return false;
} else if(!owner && !player.hasPermission("areashop.teleportfriend") && !toSign && friend) {
plugin.message(player, "teleport-noPermissionFriend");
return false;
} else if(owner && !player.hasPermission("areashop.teleportsign") && toSign) {
plugin.message(player, "teleport-noPermissionSign");
return false;
} else if(!owner && !player.hasPermission("areashop.teleportsignall") && toSign) {
} else if(!owner && !player.hasPermission("areashop.teleportsignall") && toSign && !friend) {
plugin.message(player, "teleport-noPermissionOtherSign");
return false;
} else if(!owner && !player.hasPermission("areashop.teleportfriendsign") && toSign && friend) {
plugin.message(player, "teleport-noPermissionFriendSign");
return false;
}
}

Expand Down

0 comments on commit 2c1771c

Please sign in to comment.