Skip to content

Commit

Permalink
Add a config item for disable cross-dimension warp (#117)
Browse files Browse the repository at this point in the history
* Add a config item for disable cross-dimension warp

* Add PermissionAPI.registerNode call for WARPS_CROSS_DIM
  • Loading branch information
Cyrus-Vance authored Sep 21, 2024
1 parent 360d743 commit 265b6c3
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/main/java/serverutils/ServerUtilitiesPermissions.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class ServerUtilitiesPermissions {
public static final String HOMES_TELEPORT_OTHER = "serverutilities.other_player.homes.teleport";

// Warps //
public static final String WARPS_CROSS_DIM = "serverutilities.warps.cross_dim";
public static final String WARPS_COOLDOWN = "serverutilities.warps.cooldown";
public static final String WARPS_WARMUP = "serverutilities.warps.warmup";

Expand Down Expand Up @@ -229,6 +230,10 @@ public static void registerPermissions() {
DefaultPermissionLevel.ALL,
"Allow player to see other teams claims on JourneyMap overlay");
PermissionAPI.registerNode(RANK_EDIT, DefaultPermissionLevel.OP, "Allow player to edit ranks via Admin Panel");
PermissionAPI.registerNode(
WARPS_CROSS_DIM,
DefaultPermissionLevel.ALL,
"Can use /warp to teleport to/from another dimension");

for (Block block : GameData.getBlockRegistry().typeSafeIterable()) {
String name = formatId(block);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/serverutils/command/tp/CmdWarp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@

import cpw.mods.fml.common.eventhandler.Event;
import serverutils.ServerUtilities;
import serverutils.ServerUtilitiesPermissions;
import serverutils.data.ServerUtilitiesPlayerData;
import serverutils.data.ServerUtilitiesUniverseData;
import serverutils.lib.command.CmdBase;
import serverutils.lib.command.CommandUtils;
import serverutils.lib.math.BlockDimPos;
import serverutils.lib.util.StringJoiner;
import serverutils.lib.util.permission.PermissionAPI;
import serverutils.lib.util.text_components.Notification;
import serverutils.ranks.Rank;
import serverutils.ranks.Ranks;
Expand Down Expand Up @@ -69,6 +71,11 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE
ServerUtilitiesPlayerData data = ServerUtilitiesPlayerData.get(CommandUtils.getForgePlayer(player));
data.checkTeleportCooldown(sender, ServerUtilitiesPlayerData.Timer.WARP);

if (player.dimension != p.dim
&& !PermissionAPI.hasPermission(player, ServerUtilitiesPermissions.WARPS_CROSS_DIM)) {
throw ServerUtilities.error(sender, "serverutilities.lang.warps.cross_dim");
}

IChatComponent component = ServerUtilities.lang(sender, "serverutilities.lang.warps.tp", args[0]);
Notification notification = Notification.of(TELEPORT, component);
Task task = new NotifyTask(-1, player, notification);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/serverutils/data/BackwardsCompat.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ public static void loadRanks(Rank player, Rank admin) {
if (permissionsPlayer.get("cross_dim_homes").getAsBoolean()) {
player.setPermission(ServerUtilitiesPermissions.HOMES_CROSS_DIM, true);
}
if (permissionsPlayer.get("cross_dim_warp").getAsBoolean()) {
player.setPermission(ServerUtilitiesPermissions.WARPS_CROSS_DIM, true);
}

JsonObject permissionsAdmin = LATCONFIG.get("permissions_admin").getAsJsonObject();
admin.setPermission(ServerUtilitiesPermissions.HOMES_MAX, permissionsAdmin.get("max_homes").getAsInt());
Expand All @@ -207,6 +210,9 @@ public static void loadRanks(Rank player, Rank admin) {
if (permissionsAdmin.get("cross_dim_homes").getAsBoolean()) {
admin.setPermission(ServerUtilitiesPermissions.HOMES_CROSS_DIM, true);
}
if (permissionsAdmin.get("cross_dim_warp").getAsBoolean()) {
admin.setPermission(ServerUtilitiesPermissions.WARPS_CROSS_DIM, true);
}
}

public static <E extends NBTBase> Map<String, E> toMapWithType(NBTTagCompound tag) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/serverutils/ranks/Ranks.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public boolean reload() {
vRank.setPermission(ServerUtilitiesPermissions.HOMES_WARMUP, "0s");
vRank.setPermission(ServerUtilitiesPermissions.HOMES_COOLDOWN, "1s");
vRank.setPermission(ServerUtilitiesPermissions.HOMES_CROSS_DIM, true);
vRank.setPermission(ServerUtilitiesPermissions.WARPS_CROSS_DIM, true);
vRank.setPermission("example.other_permission", true);
vRank.setPermission("example.permission_with_value", 15);

Expand All @@ -133,6 +134,7 @@ public boolean reload() {
aRank.setPermission(ServerUtilitiesPermissions.HOMES_WARMUP, "0s");
aRank.setPermission(ServerUtilitiesPermissions.HOMES_COOLDOWN, "0s");
aRank.setPermission(ServerUtilitiesPermissions.HOMES_CROSS_DIM, true);
aRank.setPermission(ServerUtilitiesPermissions.WARPS_CROSS_DIM, true);
aRank.setPermission("example.permission_with_value", 100);

if (universe.shouldLoadLatmod()) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/serverutilities/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ serverutilities.lang.warps.cooldown=You can only use warp in %s!
serverutilities.lang.warps.tp=Teleported to '%s'!
serverutilities.lang.warps.no_dp=You can only go back once!
serverutilities.lang.warps.no_pos_found=No position to go back to!
serverutilities.lang.warps.cross_dim=You can't teleport to another dimension!

# Homes
serverutilities.lang.homes.set=Home '%s' set!
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/serverutilities/lang/ja_JP.lang
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ serverutilities.lang.warps.not_set=「%s」は不明なワープ先です!
serverutilities.lang.warps.cooldown=%sでワープ可能になります!
serverutilities.lang.warps.tp=「%s」にテレポートしました!
serverutilities.lang.warps.no_dp=戻ることができるのは一度だけです!
serverutilities.lang.warps.cross_dim=別のディメンションへはテレポートできません!

# Homes
serverutilities.lang.homes.set=ホーム「%s」を設定しました!
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/assets/serverutilities/lang/ru_RU.lang
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ serverutilities.lang.warps.set=Варп '%s' установлен!
serverutilities.lang.warps.del=Варп '%s' удален!
serverutilities.lang.warps.not_set=Неизвестный варп: '%s'!
serverutilities.lang.warps.cooldown=Вы можете использовать варп только в %s!
вftbutilities.lang.warps.tp=Телепортирован в '%s'!
serverutilities.lang.warps.tp=Телепортирован в '%s'!
serverutilities.lang.warps.no_dp=Вы можете вернуться только один раз!
serverutilities.lang.warps.cross_dim=Вы не можете телепортироваться в другое измерение!


# Homes
serverutilities.lang.homes.set=Дом '%s' установлен!
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/assets/serverutilities/lang/zh_CN.lang
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ serverutilities.lang.warps.not_set=未知的传送点:“%s”!
serverutilities.lang.warps.cooldown=使用传送点传送还需 %s!
serverutilities.lang.warps.tp=传送至 “%s”!
serverutilities.lang.warps.no_dp=你只能使用一次 /back!
serverutilities.lang.warps.cross_dim=你不能传送至其它维度!

# Homes
serverutilities.lang.homes.set=家“%s”已设置!
Expand Down

0 comments on commit 265b6c3

Please sign in to comment.