Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PermissionLimitation (PERMISSION aka globalPermission) and add
PermissionKits for WORLD & CHUNK
- Loading branch information
Showing
14 changed files
with
170 additions
and
45 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
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
71 changes: 71 additions & 0 deletions
71
...-Core/src/main/java/de/Ste3et_C0st/FurnitureLib/LimitationManager/PermissionKitLimit.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,71 @@ | ||
package de.Ste3et_C0st.FurnitureLib.LimitationManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.OptionalInt; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.configuration.file.YamlConfiguration; | ||
import org.bukkit.entity.Player; | ||
|
||
import de.Ste3et_C0st.FurnitureLib.Crafting.Project; | ||
import de.Ste3et_C0st.FurnitureLib.main.Type.LimitationType; | ||
|
||
public abstract class PermissionKitLimit extends Limitation{ | ||
|
||
private static final String KEY = "Permission"; | ||
private static final String headString = KEY + "Kit"; | ||
private static final String PERMISSION = "furniture.limit."; | ||
|
||
private HashMap<String, HashMap<Project, Integer>> kitMap = new HashMap<>(); | ||
|
||
private Supplier<String> permissionConsumer = () -> PERMISSION + getEnum().name().toLowerCase() + ".<kitName>"; | ||
|
||
public PermissionKitLimit(LimitationType type) { | ||
super(type); | ||
} | ||
|
||
public YamlConfiguration loadYaml(List<String> headerList) { | ||
if(headerList.isEmpty() == false) { | ||
List<String> headerConfig = new ArrayList<>(); | ||
headerConfig.addAll(headerList); | ||
headerConfig.addAll(Arrays.asList( | ||
"----------------------", | ||
"These Limitation type support permission Kits!", | ||
"PermissionKit:", | ||
" <kitName>:", | ||
" chair: -1", | ||
"---------------------", | ||
"the permission for these kit is " + permissionConsumer.get() | ||
)); | ||
headerList = headerConfig; | ||
} | ||
return super.loadYaml(headerList); | ||
} | ||
|
||
@Override | ||
protected void ioProjectLimit(String headerString, Project project, YamlConfiguration configuration) { | ||
if(configuration.isConfigurationSection(headString)) { | ||
configuration.getConfigurationSection(headString).getKeys(false).forEach(key -> { | ||
final String kit = headString + "." + key; | ||
if(configuration.contains(kit + "." + project.getName())) { | ||
final int amount = configuration.getInt(kit + "." + project.getName(), -1); | ||
final HashMap<Project, Integer> kitMap = this.kitMap.getOrDefault(kit, new HashMap<>()); | ||
kitMap.put(project, amount); | ||
this.kitMap.put(key, kitMap); | ||
} | ||
}); | ||
} | ||
|
||
super.ioProjectLimit(headerString, project, configuration); | ||
} | ||
|
||
public OptionalInt getKitLimit(Project project, Location location, Player player) { | ||
final List<String> permissionMap = kitMap.keySet().stream().filter(entry -> player.hasPermission(permissionConsumer.get().replace("<kitName>", entry.toLowerCase()))).collect(Collectors.toList()); | ||
return permissionMap.stream().filter(kitMap::containsKey).map(kitMap::get).mapToInt(entry -> entry.get(project)).max(); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...ore/src/main/java/de/Ste3et_C0st/FurnitureLib/LimitationManager/PermissionLimitation.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,52 @@ | ||
package de.Ste3et_C0st.FurnitureLib.LimitationManager; | ||
|
||
import java.util.function.Predicate; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.entity.Player; | ||
|
||
import de.Ste3et_C0st.FurnitureLib.Crafting.Project; | ||
import de.Ste3et_C0st.FurnitureLib.main.FurnitureConfig; | ||
import de.Ste3et_C0st.FurnitureLib.main.FurnitureManager; | ||
import de.Ste3et_C0st.FurnitureLib.main.ObjectID; | ||
import de.Ste3et_C0st.FurnitureLib.main.Type.LimitationType; | ||
|
||
public class PermissionLimitation extends Limitation{ | ||
|
||
private static final String PERMISSION = "furniture.globallimit."; | ||
|
||
public PermissionLimitation() { | ||
super(LimitationType.PERMISSION); | ||
} | ||
|
||
@Override | ||
public int getAmount(Predicate<ObjectID> projectAmount) { | ||
return (int) FurnitureManager.getInstance().getAllExistObjectIDs().filter(projectAmount).count(); | ||
} | ||
|
||
@Override | ||
public boolean canPlace(Location location, Project project, Player player) { | ||
return getAmount(buildFilter(location, project, player)) < getLimit(project, location, player); | ||
} | ||
|
||
@Override | ||
public int getLimit(Project project, Location location, Player player) { | ||
for (int i = FurnitureConfig.getFurnitureConfig().getLimitGlobal(); i > 0; i--) { | ||
if (player.hasPermission(PERMISSION + i)) { | ||
return i; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
@Override | ||
public void writeConfig() {} | ||
|
||
@Override | ||
public void updateConfig(Project project) {} | ||
|
||
@Override | ||
public Predicate<ObjectID> buildFilter(Location location, Project project, Player player) { | ||
return objectID -> objectID.hasProjectOBJ() && objectID.getUUID().equals(player.getUniqueId()); | ||
} | ||
} |
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
Binary file modified
BIN
+0 Bytes
(100%)
buildSrc/.gradle/7.2/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
buildSrc/.gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.