-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from Nuytemans-Dieter/v4.0.1
V4.0.1
- Loading branch information
Showing
21 changed files
with
156 additions
and
69 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
2 changes: 1 addition & 1 deletion
2
src/main/java/be/betterplugins/bettersleeping/commands/BuffsCommand.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
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
2 changes: 1 addition & 1 deletion
2
src/main/java/be/betterplugins/bettersleeping/listeners/BedEventListener.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
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
56 changes: 56 additions & 0 deletions
56
src/main/java/be/betterplugins/bettersleeping/model/permissions/PermissionsCache.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,56 @@ | ||
package be.betterplugins.bettersleeping.model.permissions; | ||
|
||
import be.betterplugins.bettersleeping.messaging.ScreenMessenger; | ||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.event.EventHandler; | ||
import org.bukkit.event.Listener; | ||
import org.bukkit.event.player.PlayerQuitEvent; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
@Singleton | ||
public class PermissionsCache implements Listener | ||
{ | ||
|
||
Map<UUID, Map<String, Boolean>> permissionsCacheMap; | ||
|
||
@Inject | ||
public PermissionsCache(JavaPlugin plugin) | ||
{ | ||
this.permissionsCacheMap = new HashMap<>(); | ||
|
||
// Argument may be null in unit tests | ||
if (plugin != null) | ||
plugin.getServer().getPluginManager().registerEvents(this, plugin); | ||
} | ||
|
||
public boolean hasPermission(Player player, String permission) | ||
{ | ||
Map<String, Boolean> permissionMap = permissionsCacheMap.get(player.getUniqueId()); | ||
|
||
if (permissionMap == null) | ||
{ | ||
permissionMap = new HashMap<>(); | ||
} | ||
|
||
if (!permissionMap.containsKey(permission)) | ||
{ | ||
permissionMap.put(permission, player.hasPermission(permission)); | ||
} | ||
|
||
permissionsCacheMap.put(player.getUniqueId(), permissionMap); | ||
|
||
return permissionMap.get(permission); | ||
} | ||
|
||
@EventHandler | ||
public void onPlayerLeave (PlayerQuitEvent playerQuitEvent) | ||
{ | ||
this.permissionsCacheMap.remove(playerQuitEvent.getPlayer().getUniqueId()); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/be/betterplugins/bettersleeping/model/sleeping/SleepWorld.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
2 changes: 1 addition & 1 deletion
2
src/main/java/be/betterplugins/bettersleeping/model/sleeping/SleepWorldManager.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
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
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,25 @@ | ||
package mock; | ||
|
||
import be.betterplugins.bettersleeping.model.permissions.PermissionsCache; | ||
import org.bukkit.entity.Player; | ||
import org.bukkit.plugin.java.JavaPlugin; | ||
|
||
import java.util.HashSet; | ||
|
||
public class MockPermissionsCache extends PermissionsCache | ||
{ | ||
|
||
HashSet<Player> playersWithBypassPermission; | ||
|
||
public MockPermissionsCache(JavaPlugin plugin, HashSet<Player> playersWithBypassPermission) | ||
{ | ||
super(plugin); | ||
this.playersWithBypassPermission = playersWithBypassPermission; | ||
} | ||
|
||
@Override | ||
public boolean hasPermission(Player player, String permission) | ||
{ | ||
return playersWithBypassPermission.contains(player); | ||
} | ||
} |
Oops, something went wrong.