-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proper config and player roles compat
- Loading branch information
Showing
25 changed files
with
435 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/main/java/net/modfest/fireblanket/compat/roles/PlayerRolesCompat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package net.modfest.fireblanket.compat.roles; | ||
|
||
import dev.gegy.roles.api.PlayerRolesApi; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
|
||
public class PlayerRolesCompat { | ||
public static boolean isLoaded = false; | ||
|
||
public static void init() { | ||
if (FabricLoader.getInstance().isModLoaded("player_roles")) { | ||
isLoaded = true; | ||
} | ||
} | ||
|
||
public static boolean isNetadmin(PlayerEntity player) { | ||
return is(player, "netadmin"); | ||
} | ||
|
||
public static boolean isOrganizer(PlayerEntity player) { | ||
return is(player, "organizer"); | ||
} | ||
|
||
public static boolean isBuilder(PlayerEntity player) { | ||
return is(player, "builder") || is(player, "fixer"); | ||
} | ||
|
||
private static boolean is(PlayerEntity player, String id) { | ||
return PlayerRolesApi.lookup().byPlayer(player).stream().anyMatch(r -> r.getId().equals(id)); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/net/modfest/fireblanket/compat/roles/Roles.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package net.modfest.fireblanket.compat.roles; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.server.integrated.IntegratedServer; | ||
|
||
public class Roles { | ||
private static boolean isSingleplayer(PlayerEntity player) { | ||
return player.getEntityWorld().getServer() instanceof IntegratedServer; | ||
} | ||
|
||
public static boolean isNetadmin(PlayerEntity player) { | ||
if (player == null) { | ||
return false; | ||
} | ||
|
||
if (PlayerRolesCompat.isLoaded) { | ||
if (PlayerRolesCompat.isNetadmin(player)) { | ||
return true; | ||
} | ||
} | ||
|
||
if (isSingleplayer(player)) { | ||
return true; | ||
} | ||
|
||
// check fb config as well | ||
return false; | ||
} | ||
|
||
public static boolean isOrganizer(PlayerEntity player) { | ||
if (player == null) { | ||
return false; | ||
} | ||
|
||
if (isNetadmin(player)) { | ||
return true; | ||
} | ||
|
||
if (PlayerRolesCompat.isLoaded) { | ||
if (PlayerRolesCompat.isOrganizer(player)) { | ||
return true; | ||
} | ||
} | ||
|
||
if (isSingleplayer(player)) { | ||
return true; | ||
} | ||
|
||
// check fb config as well | ||
return false; | ||
} | ||
|
||
public static boolean isBuilder(PlayerEntity player) { | ||
if (player == null) { | ||
return false; | ||
} | ||
|
||
if (isOrganizer(player)) { | ||
return true; | ||
} | ||
|
||
if (PlayerRolesCompat.isLoaded) { | ||
if (PlayerRolesCompat.isBuilder(player)) { | ||
return true; | ||
} | ||
} | ||
|
||
if (isSingleplayer(player)) { | ||
return true; | ||
} | ||
|
||
// check fb config as well | ||
return false; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/net/modfest/fireblanket/config/ConfigParsers.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package net.modfest.fireblanket.config; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class ConfigParsers { | ||
public static final ParseFunc<List<String>> STRING_LIST = in -> { | ||
return Arrays.asList(in.split(",")); | ||
}; | ||
|
||
public static final ParseFunc<String> STRING = in -> in; | ||
|
||
public static final ParseFunc<Integer> INTEGER = in -> { | ||
try { | ||
return Integer.parseInt(in); | ||
} catch (Exception e) { | ||
throw new ParseException("Unknown integer value: " + in); | ||
} | ||
}; | ||
|
||
public static final ParseFunc<Boolean> BOOLEAN = in -> { | ||
if ("yes".equals(in) || "true".equals(in)) { | ||
return true; | ||
} | ||
|
||
if ("no".equals(in) || "false".equals(in)) { | ||
return false; | ||
} | ||
|
||
throw new ParseException("Unknown boolean value: " + in); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package net.modfest.fireblanket.config; | ||
|
||
public record ConfigSpec<T>(String name, String prettyName, String description, String defaultValue, ParseFunc<T> parser) { | ||
} |
Oops, something went wrong.