Skip to content

Commit 320d478

Browse files
authored
Update 2.0: Implement developer api and readme
Merge pull request #8 from KCodeYT/next/2.0
2 parents d4e1be6 + fa77ced commit 320d478

26 files changed

+625
-143
lines changed

.github/images/banner.png

48.7 KB
Loading

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111
- name: Checkout github repository
1212
uses: actions/checkout@v3
1313

14-
- name: Set up JDK 17
14+
- name: Set up JDK 8
1515
uses: actions/setup-java@v3
1616
with:
17-
java-version: '17'
17+
java-version: '8'
1818
distribution: 'temurin'
1919
cache: maven
2020

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
![banner](./.github/images/banner.png)
2+
3+
What is this?
4+
------------------------------
5+
6+
This project is a plugin for the nukkit server software environment.
7+
This plugin adds player heads to the server.
8+
9+
How can I download this plugin?
10+
------------------------------
11+
12+
You can find the downloads on the [releases section](https://github.com/KCodeYT/Heads/releases) of this github page.
13+
There you can find the LATEST jar file of this plugin.
14+
15+
How do I give myself a head?
16+
------------------------------
17+
18+
1. Open the chat in your client.
19+
2. Ensure you have the operator status on the server or have the permission "heads.command.head",
20+
otherwise you will not be able to use this command.
21+
3. Type /head followed by the name of the skull owner.
22+
(This can be any player which has joined the server once
23+
or a java editiopn player)
24+
4. You will see a head appear in your inventory if the player was found.
25+
If the player was not found, you will see a message in the chat.
26+
27+
Developer API
28+
------------------------------
29+
30+
```java
31+
import cn.nukkit.Player;
32+
import de.kcodeyt.heads.api.HeadAPI;
33+
34+
public class YourPlugin {
35+
36+
public static void giveHeadByName(Player player, String name) {
37+
HeadAPI.giveHead(player, name).whenComplete((result, error) -> {
38+
if(result == null || error != null) {
39+
// something went wrong
40+
return;
41+
}
42+
43+
if(!result.isSuccess()) {
44+
// use result.getCause() to find out why the head was not given
45+
return;
46+
}
47+
48+
// head was given.
49+
});
50+
}
51+
52+
}
53+
```

pom.xml

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66

77
<groupId>de.kcodeyt</groupId>
88
<artifactId>Heads</artifactId>
9-
<version>1.1.1</version>
9+
<version>2.0.0</version>
10+
11+
<properties>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
15+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
16+
</properties>
1017

1118
<repositories>
1219
<repository>
@@ -31,20 +38,6 @@
3138
</repository>
3239
</repositories>
3340

34-
<build>
35-
<plugins>
36-
<plugin>
37-
<groupId>org.apache.maven.plugins</groupId>
38-
<artifactId>maven-compiler-plugin</artifactId>
39-
<version>3.1</version>
40-
<configuration>
41-
<source>8</source>
42-
<target>8</target>
43-
</configuration>
44-
</plugin>
45-
</plugins>
46-
</build>
47-
4841
<dependencies>
4942
<dependency>
5043
<groupId>cn.nukkit</groupId>
@@ -57,4 +50,19 @@
5750
<version>1.18.24</version>
5851
</dependency>
5952
</dependencies>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-compiler-plugin</artifactId>
59+
<version>3.1</version>
60+
<configuration>
61+
<source>1.8</source>
62+
<target>1.8</target>
63+
<encoding>UTF-8</encoding>
64+
</configuration>
65+
</plugin>
66+
</plugins>
67+
</build>
6068
</project>

src/main/java/de/kcodeyt/heads/Heads.java

Lines changed: 4 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
import cn.nukkit.block.Block;
2020
import cn.nukkit.blockentity.BlockEntity;
2121
import cn.nukkit.entity.Entity;
22-
import cn.nukkit.item.Item;
23-
import cn.nukkit.nbt.tag.CompoundTag;
2422
import cn.nukkit.plugin.PluginBase;
2523
import cn.nukkit.utils.Config;
2624
import de.kcodeyt.heads.block.BlockSkull;
@@ -29,9 +27,8 @@
2927
import de.kcodeyt.heads.entity.EntitySkull;
3028
import de.kcodeyt.heads.lang.Language;
3129
import de.kcodeyt.heads.listener.EventListener;
32-
import de.kcodeyt.heads.util.*;
33-
import de.kcodeyt.heads.util.api.SkinAPI;
34-
import de.kcodeyt.heads.util.api.SkinData;
30+
import de.kcodeyt.heads.util.LocalSkinAPI;
31+
import de.kcodeyt.heads.util.PluginHolder;
3532
import lombok.Getter;
3633

3734
import java.io.BufferedReader;
@@ -42,40 +39,15 @@
4239

4340
public class Heads extends PluginBase {
4441

45-
private static final String DEFAULT_LANGUAGE = "en_US";
46-
47-
public static final RuntimeException EXCEPTION = new RuntimeException();
48-
4942
@Getter
5043
private Language language;
5144

5245
@Override
5346
public void onLoad() {
5447
PluginHolder.init(this);
5548

49+
this.saveResource("config.yml");
5650
final Config config = this.getConfig();
57-
config.reload();
58-
if(!config.exists("skull-scale")) {
59-
config.set("skull-scale", "VANILLA");
60-
config.save();
61-
}
62-
if(!config.exists("save-skin-cache")) {
63-
config.set("save-skin-cache", true);
64-
config.save();
65-
}
66-
if(!config.exists("skin-cache-folder")) {
67-
config.set("skin-cache-folder", "./skins/");
68-
config.save();
69-
}
70-
if(!config.exists("local-skin-folder")) {
71-
config.set("local-skin-folder", "./local_skins/");
72-
config.save();
73-
}
74-
75-
if(!config.exists("default_lang")) {
76-
config.set("default_lang", DEFAULT_LANGUAGE);
77-
config.save();
78-
}
7951

8052
final File langDir = new File(this.getDataFolder(), "lang");
8153
final File[] files = langDir.listFiles();
@@ -96,7 +68,7 @@ public void onLoad() {
9668
}
9769

9870
try {
99-
final String defaultLang = config.getString("default_lang");
71+
final String defaultLang = config.getString("default-lang");
10072

10173
this.language = new Language(langDir, defaultLang);
10274
this.getLogger().info("This plugin is using the " + this.language.getDefaultLang() + " as default language file!");
@@ -134,38 +106,4 @@ public void onDisable() {
134106
LocalSkinAPI.saveNameLookup();
135107
}
136108

137-
public static ScheduledFuture<ItemResult> createItem(HeadInput input) {
138-
switch(input.getType()) {
139-
case LOCAL:
140-
final String skinId = LocalSkinAPI.getLatestSkinId(input.getName());
141-
if(skinId == null) return ScheduledFuture.completed(null);
142-
143-
final String originalName = LocalSkinAPI.getPlayerName(skinId);
144-
145-
return ScheduledFuture.completed(new ItemResult(Heads.createItemByOwner(new SkullOwner(skinId, originalName, null)), originalName));
146-
case PLAYER:
147-
return SkinAPI.getSkin(input.getName()).thenApply(skinResponse -> {
148-
if(skinResponse.isSuccess()) {
149-
final SkinData skinData = skinResponse.getSkinData();
150-
return new ItemResult(Heads.createItemByOwner(new SkullOwner(skinData.getSkinOwnerUniqueId(), skinData.getSkinOwnerName(), skinData.getTexture())), skinData.getSkinOwnerName());
151-
}
152-
throw EXCEPTION;
153-
});
154-
case TEXTURE:
155-
return ScheduledFuture.completed(new ItemResult(Heads.createItemByOwner(new SkullOwner(input.getUniqueId(), null, input.getTexture())), null));
156-
}
157-
return ScheduledFuture.completed(null);
158-
}
159-
160-
public static Item createItemByOwner(SkullOwner skullOwner) {
161-
final Item item = Heads.createItemByType(3).setNamedTag(new CompoundTag().putCompound("SkullOwner", skullOwner.toCompoundTag()));
162-
if(skullOwner.getName() != null)
163-
item.setCustomName("§r§f" + skullOwner.getName() + "'s Head");
164-
return item;
165-
}
166-
167-
public static Item createItemByType(int skullType) {
168-
return Item.get(Item.SKULL, skullType, 1);
169-
}
170-
171109
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*
2+
* Copyright 2022 KCodeYT
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package de.kcodeyt.heads.api;
18+
19+
import lombok.AccessLevel;
20+
import lombok.AllArgsConstructor;
21+
import lombok.Value;
22+
23+
@Value
24+
@AllArgsConstructor(access = AccessLevel.PRIVATE)
25+
public class GiveSkullResult {
26+
27+
/**
28+
* Signals that the skull owner could not be resolved because the skull owner had an invalid name.
29+
*/
30+
public static final GiveSkullResult FAILURE_INVALID_NAME = new GiveSkullResult(false, null, FailureCause.INVALID_NAME);
31+
32+
/**
33+
* Signals that the skull owner could not be resolved because the skull owner was not found.
34+
*/
35+
public static final GiveSkullResult FAILURE_PLAYER_NOT_FOUND = new GiveSkullResult(false, null, FailureCause.PLAYER_NOT_FOUND);
36+
37+
/**
38+
* Creates a new {@link GiveSkullResult} with the given player name that signals
39+
* that the skull owner was successfully resolved.
40+
*
41+
* @param playerName the name of the skull owner that was resolved.
42+
* @return a new successful {@link GiveSkullResult} with the given player name.
43+
*/
44+
public static GiveSkullResult success(String playerName) {
45+
return new GiveSkullResult(true, playerName, null);
46+
}
47+
48+
boolean success;
49+
String playerName;
50+
FailureCause cause;
51+
52+
public enum FailureCause {
53+
INVALID_NAME,
54+
PLAYER_NOT_FOUND
55+
}
56+
57+
}

0 commit comments

Comments
 (0)