|
| 1 | +# Locker |
| 2 | + |
| 3 | +Locker is paper plugin with additional api to allow developers an easier control |
| 4 | +over player names and especially their possible disguises. Locker offers developers |
| 5 | +the ability to easily change the whole appearance of a player to another player (group). |
| 6 | +Thereby, the uuid, the name as well as the skin can be freely changed by modifying the |
| 7 | +clientbound packets, which provides the most flexibility. |
| 8 | + |
| 9 | +1. [Installation](#installation) |
| 10 | + |
| 11 | + 1.1 [Adding to your server](#adding-to-your-server) |
| 12 | + |
| 13 | + 1.2 [Adding to your plugin](#adding-to-your-plugin) |
| 14 | +2. [Usage](#usage) |
| 15 | + |
| 16 | + 2.1 [Explanation](#explanation) |
| 17 | + |
| 18 | + 2.2 [Setup](#setup) |
| 19 | + |
| 20 | + 2.3 [Update Look](#update-look) |
| 21 | + |
| 22 | + 2.4 [Components](#components) |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +### Adding to your server |
| 27 | + |
| 28 | +Locker works as a standalone plugin and offers every plugin additionally an api. |
| 29 | +Because of that, in order for Locker to work you must include the locker.jar |
| 30 | +of the current release in your plugins directory. |
| 31 | + |
| 32 | +### Adding to your plugin |
| 33 | + |
| 34 | +If you want to add the locker `api` or the locker `components` to your plugin, |
| 35 | +you must first add following repository to your build file: |
| 36 | + |
| 37 | +#### Maven |
| 38 | + |
| 39 | +```xml |
| 40 | +<repository> |
| 41 | + <id>qetz-repository</id> |
| 42 | + <url>https://repo.qetz.de/artifactory/repo-public</url> |
| 43 | +</repository> |
| 44 | +``` |
| 45 | + |
| 46 | +#### Gradle |
| 47 | + |
| 48 | +```groovy |
| 49 | +maven { |
| 50 | + url 'https://repo.qetz.de/artifactory/repo-public' |
| 51 | + metadataSources { |
| 52 | + mavenPom() |
| 53 | + gradleMetadata() |
| 54 | + artifact() |
| 55 | + } |
| 56 | +} |
| 57 | +``` |
| 58 | + |
| 59 | +Afterwards you can add the `api` and if you wish the additional `components`: |
| 60 | + |
| 61 | +#### Maven |
| 62 | + |
| 63 | +```xml |
| 64 | +<dependency> |
| 65 | + <groupId>qetz.locker</groupId> |
| 66 | + <artifactId>api</artifactId> |
| 67 | + <version>1.0.0</version> |
| 68 | + <scope>compile</scope> |
| 69 | +</dependency> |
| 70 | + |
| 71 | +<!-- Optionally components --> |
| 72 | +<dependency> |
| 73 | + <groupId>qetz.locker</groupId> |
| 74 | + <artifactId>components</artifactId> |
| 75 | + <version>1.0.0</version> |
| 76 | +</dependency> |
| 77 | +``` |
| 78 | + |
| 79 | +#### Gradle |
| 80 | + |
| 81 | +```groovy |
| 82 | +compileOnly 'qetz.locker:api:1.0.0' |
| 83 | +
|
| 84 | +// Optionally components |
| 85 | +implementation 'qetz.locker:components:1.0.0' |
| 86 | +``` |
| 87 | + |
| 88 | +## Usage |
| 89 | + |
| 90 | +### Explanation |
| 91 | + |
| 92 | +First, to make things a little clearer: Every player has a `Look` based upon |
| 93 | +a set of outfits. An `Outfit` describes the actual name and skin other players |
| 94 | +may see later on. However, the `Look` decides which player should see which `Outfit`. |
| 95 | +For example, a staff member can have a Look based upon two Outfits: One `Outfit` |
| 96 | +displaying the real staff member and one disguised `Outfit` for every normal player, |
| 97 | +who shouldn't be able to see the actual staff member. |
| 98 | + |
| 99 | +The `api` module provides the bare-minimum to build a plugin on Locker. However, |
| 100 | +basic or repetitive components like a `SingleLook` (A `Look`, which only shows one `Outfit`) |
| 101 | +already exists in the `components` module, so maybe you should take a look there |
| 102 | +before you start coding your own version. |
| 103 | + |
| 104 | +**Note:** The whole project depends on [Guice](https://github.com/google/guice). |
| 105 | +So if you don't use or know that already, you should check out that before. |
| 106 | + |
| 107 | +### Setup |
| 108 | + |
| 109 | +You access `Locker` from Bukkit's ServiceManager: |
| 110 | +```java |
| 111 | + var locker = Bukkit.getServicesManager().load(Locker.class); |
| 112 | +``` |
| 113 | +Alternatively you can use the `LockerProvider` in the `components` module. |
| 114 | + |
| 115 | +<br> |
| 116 | + |
| 117 | +In order for Locker to work, you must register a `LookFactory`, which handles |
| 118 | +the creation of a Look for every player. You can add a LookFactory via `Locker`: |
| 119 | + |
| 120 | +```java |
| 121 | + var locker = injector.getInstance(Locker.class) |
| 122 | + var yourFactory = injector.getInstance(LookFactory.class); |
| 123 | + locker.registerFactory(yourFactory); |
| 124 | +``` |
| 125 | +If you just want to use the original player's outfits, you can use the `OriginalLookFactory` |
| 126 | +from the `components` module. |
| 127 | + |
| 128 | +<br> |
| 129 | + |
| 130 | +If you want to access the original Outfit of a player, you can use `Outfit#fromPlayer`. |
| 131 | + |
| 132 | +### Update Look |
| 133 | + |
| 134 | +If you want to update the Look of a player, you can also use the `Locker` object: |
| 135 | + |
| 136 | +```java |
| 137 | + var locker = injector.getInstance(Locker.class); |
| 138 | + locker.updateLock(player.getUniqueId(), factory.createNewLook(player)); |
| 139 | +``` |
| 140 | + |
| 141 | +You can see a Look-update in the `examples` module in the context of |
| 142 | +[nicks](https://github.com/Qetzing/locker/tree/main/examples/src/main/java/qetz/locker/example/nick). |
| 143 | + |
| 144 | +### Components |
| 145 | + |
| 146 | +Here you can see already existing components: |
| 147 | + |
| 148 | +#### LockerProvider |
| 149 | + |
| 150 | +A `Provider` for the `Locker` object. You can use it in your Guice module for example: |
| 151 | +```java |
| 152 | + @Override |
| 153 | + protected void configure() { |
| 154 | + bind(Locker.class).toProvider(LockerProvider.create()) |
| 155 | + } |
| 156 | +``` |
| 157 | + |
| 158 | +#### NickedLook |
| 159 | + |
| 160 | +This is a `Look` consisting of two Outfits, one original and one nicked. Furthermore, |
| 161 | +you have a bypass permission to decide which player should see the original or the nicked |
| 162 | +outfit: |
| 163 | + |
| 164 | +```java |
| 165 | + private static final bypassPermission = "user.nick"; |
| 166 | + |
| 167 | + var original = Outfit.fromPlayer(player); |
| 168 | + var nicked = factory.createNickedOutfit(player); |
| 169 | + var look = NickedLook.with(bypassPermission, original, nicked); |
| 170 | +``` |
| 171 | + |
| 172 | +#### OriginalLookFactory |
| 173 | + |
| 174 | +This `LookFactory` simply returns a [SingleLook](#single-look) with the player's original |
| 175 | +outfit. |
| 176 | + |
| 177 | +#### PermissionFilteredLook |
| 178 | + |
| 179 | +The `PermissionFilteredLook` is a `Look` consisting of a Map with Outfits and their |
| 180 | +according view-permission. This Look decides which Outfit a player should see based on |
| 181 | +the receiver's permission. I.e., you pass a `LinkedHashMap<String, Outfit> outfits` |
| 182 | +with a permission for each outfit. |
| 183 | + |
| 184 | +On top of that, you pass an `UnknownPolicy`, which decides which Outfit should be selected, |
| 185 | +if not other Outfit could be found. You can decide between three options: |
| 186 | + |
| 187 | + - Throw |
| 188 | + - Last |
| 189 | + - Explicit |
| 190 | + |
| 191 | +Throw: When choosing `Throw`, an exception is thrown if no suitable Outfit could be found |
| 192 | + |
| 193 | +Last: When choosing `Last`, the last Outfit in the `outfits` Map is used |
| 194 | + |
| 195 | +Explicit: When choosing `Explicit`, you pass an additional, explicit `Outfit` as a |
| 196 | +fallback outfit. |
| 197 | + |
| 198 | +```java |
| 199 | + var look = PermissionFilteredLook.newBuilder() |
| 200 | + .addLook("vip", vipOutfit) |
| 201 | + .withUnknownPolicy(UnknownPolicy.Explicit) |
| 202 | + .withExplicit(defaultOutfit) |
| 203 | + .create(); |
| 204 | +``` |
| 205 | + |
| 206 | +#### Single Look |
| 207 | + |
| 208 | +This is a simple `Look`, which only consists of one `Outfit`, which will be returned |
| 209 | +everytime. |
0 commit comments