Skip to content

Commit 62e08f0

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 11cab72 + 1d0f49e commit 62e08f0

File tree

4 files changed

+243
-145
lines changed

4 files changed

+243
-145
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ We provide some documentation on how to migrate your existing plugin to use the
3535
<scope>provided</scope>
3636
</dependency>
3737
```
38+
**Or alternatively, with Gradle:**
39+
```kotlin
40+
repsitories {
41+
maven {
42+
url = uri('https://mvn.exceptionflug.de/repository/exceptionflug-public/')
43+
}
44+
}
45+
46+
dependencies {
47+
compileOnly("dev.simplix:protocolize-api:2.2.1")
48+
}
49+
```
3850
### Install the plugin
3951
In order to use Protocolize, you have to install it onto your proxy server. Protocolize is supporting BungeeCord and Velocity proxy servers.
4052

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package dev.simplix.protocolize.api.item;
2+
3+
import java.util.List;
4+
import java.util.Set;
5+
6+
public interface BaseItemStack {
7+
boolean flagSet(ItemFlag flag);
8+
9+
void itemFlag(ItemFlag flag, boolean active);
10+
11+
Set<ItemFlag> itemFlags();
12+
13+
boolean canBeStacked(ItemStack stack);
14+
15+
<T> T displayName();
16+
17+
<T> T displayName(boolean legacyString);
18+
19+
ItemStack displayName(String legacyName);
20+
21+
ItemStack displayName(Object displayName);
22+
23+
<T> List<T> lore();
24+
25+
<T> List<T> lore(boolean legacyString);
26+
27+
void lore(List<?> list, boolean legacyString);
28+
29+
void lore(int index, String legacyText);
30+
31+
void lore(int index, Object component);
32+
33+
void addToLore(String legacyText);
34+
35+
void addToLore(Object component);
36+
37+
ItemStack deepClone();
38+
39+
ItemStack deepClone(int protocolVersion);
40+
41+
dev.simplix.protocolize.data.ItemType itemType();
42+
43+
net.querz.nbt.tag.CompoundTag nbtData();
44+
45+
byte amount();
46+
47+
short durability();
48+
49+
int hideFlags();
50+
51+
ItemStack itemType(dev.simplix.protocolize.data.ItemType itemType);
52+
53+
ItemStack nbtData(net.querz.nbt.tag.CompoundTag nbtData);
54+
55+
ItemStack amount(byte amount);
56+
57+
ItemStack durability(short durability);
58+
59+
ItemStack hideFlags(int hideFlags);
60+
}

protocolize-api/src/main/java/dev/simplix/protocolize/api/item/ItemStack.java

Lines changed: 160 additions & 142 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
import dev.simplix.protocolize.data.ItemType;
99
import io.netty.buffer.ByteBuf;
1010
import io.netty.buffer.Unpooled;
11+
import java.util.*;
1112
import lombok.*;
1213
import lombok.experimental.Accessors;
1314
import net.querz.nbt.tag.CompoundTag;
1415

15-
import java.util.*;
16-
1716
/**
1817
* This class represents a Minecraft item stack. <br>
1918
* <br>
@@ -26,145 +25,164 @@
2625
@Accessors(fluent = true)
2726
@EqualsAndHashCode
2827
@ToString
29-
public class ItemStack {
30-
31-
public static final ItemStack NO_DATA = new ItemStack(null);
32-
33-
private static final ComponentConverter CONVERTER = Protocolize.getService(ComponentConverterProvider.class)
34-
.platformConverter();
35-
36-
@Getter(AccessLevel.PACKAGE)
37-
@Setter(AccessLevel.PACKAGE)
38-
private String displayNameJson;
39-
40-
@Getter(AccessLevel.PACKAGE)
41-
@Setter(AccessLevel.PACKAGE)
42-
private List<String> loreJson = new ArrayList<>();
43-
44-
private ItemType itemType;
45-
private CompoundTag nbtData = new CompoundTag();
46-
private byte amount;
47-
private short durability;
48-
private int hideFlags;
49-
50-
public ItemStack(ItemType itemType) {
51-
this(itemType, 1);
52-
}
53-
54-
public ItemStack(ItemType itemType, int amount) {
55-
this(itemType, amount, (short) -1);
56-
}
57-
58-
public ItemStack(ItemType itemType, int amount, short durability) {
59-
this.itemType = itemType;
60-
this.amount = (byte) amount;
61-
this.durability = durability;
62-
}
63-
64-
public boolean flagSet(ItemFlag flag) {
65-
return (hideFlags & (1 << flag.getBitIndex())) == 1;
66-
}
67-
68-
public void itemFlag(ItemFlag flag, boolean active) {
69-
if (active)
70-
hideFlags |= (1 << flag.getBitIndex());
71-
else
72-
hideFlags &= ~(1 << flag.getBitIndex());
73-
}
74-
75-
public Set<ItemFlag> itemFlags() {
76-
Set<ItemFlag> flags = new HashSet<>();
77-
for (ItemFlag flag : ItemFlag.values()) {
78-
if (flagSet(flag))
79-
flags.add(flag);
80-
}
81-
return Collections.unmodifiableSet(flags);
82-
}
83-
84-
public boolean canBeStacked(ItemStack stack) {
85-
return stack.itemType() == itemType && stack.nbtData().equals(nbtData);
86-
}
87-
88-
public <T> T displayName() {
89-
return displayName(false);
90-
}
91-
92-
public <T> T displayName(boolean legacyString) {
93-
if (displayNameJson == null) {
94-
return null;
95-
}
96-
if (legacyString) {
97-
return (T) CONVERTER.toLegacyText(CONVERTER.fromJson(displayNameJson));
98-
} else {
99-
return (T) CONVERTER.fromJson(displayNameJson);
100-
}
101-
}
102-
103-
public ItemStack displayName(String legacyName) {
104-
this.displayNameJson = CONVERTER.toJson(CONVERTER.fromLegacyText(legacyName));
105-
return this;
106-
}
107-
108-
public ItemStack displayName(Object displayName) {
109-
this.displayNameJson = CONVERTER.toJson(displayName);
110-
return this;
111-
}
112-
113-
public <T> List<T> lore() {
114-
return lore(false);
115-
}
116-
117-
public <T> List<T> lore(boolean legacyString) {
118-
List<T> out = new ArrayList<>();
119-
for (String line : loreJson) {
120-
if (legacyString) {
121-
out.add((T) CONVERTER.toLegacyText(CONVERTER.fromJson(line)));
122-
} else {
123-
out.add((T) CONVERTER.fromJson(line));
124-
}
125-
}
126-
return out;
127-
}
128-
129-
public void lore(List<?> list, boolean legacyString) {
130-
Preconditions.checkNotNull(list, "The lore list cannot be null.");
131-
List<String> out = new ArrayList<>();
132-
for (Object line : list) {
133-
if (legacyString) {
134-
out.add(CONVERTER.toJson(CONVERTER.fromLegacyText((String) line)));
135-
} else {
136-
out.add(CONVERTER.toJson(line));
137-
}
138-
}
139-
this.loreJson = out;
140-
}
141-
142-
public void lore(int index, String legacyText) {
143-
loreJson.set(index, CONVERTER.toJson(CONVERTER.fromLegacyText(legacyText)));
144-
}
145-
146-
public void lore(int index, Object component) {
147-
loreJson.set(index, CONVERTER.toJson(component));
148-
}
149-
150-
public void addToLore(String legacyText) {
151-
loreJson.add(CONVERTER.toJson(CONVERTER.fromLegacyText(legacyText)));
152-
}
153-
154-
public void addToLore(Object component) {
155-
loreJson.add(CONVERTER.toJson(component));
156-
}
157-
158-
public ItemStack deepClone() {
159-
return deepClone(ProtocolVersions.MINECRAFT_LATEST);
160-
}
161-
162-
public ItemStack deepClone(int protocolVersion) {
163-
ByteBuf buf = Unpooled.buffer();
164-
ItemStackSerializer.write(buf, this, protocolVersion);
165-
ItemStack itemStack = ItemStackSerializer.read(buf, protocolVersion);
166-
buf.release();
167-
return itemStack;
168-
}
28+
public class ItemStack implements BaseItemStack {
29+
30+
public static final ItemStack NO_DATA = new ItemStack(null);
31+
32+
private static final ComponentConverter CONVERTER = Protocolize.getService(ComponentConverterProvider.class)
33+
.platformConverter();
34+
35+
@Getter(AccessLevel.PACKAGE)
36+
@Setter(AccessLevel.PACKAGE)
37+
private String displayNameJson;
38+
39+
@Getter(AccessLevel.PACKAGE)
40+
@Setter(AccessLevel.PACKAGE)
41+
private List<String> loreJson = new ArrayList<>();
42+
43+
private ItemType itemType;
44+
private CompoundTag nbtData = new CompoundTag();
45+
private byte amount;
46+
private short durability;
47+
private int hideFlags;
48+
49+
public ItemStack(ItemType itemType) {
50+
this(itemType, 1);
51+
}
52+
53+
public ItemStack(ItemType itemType, int amount) {
54+
this(itemType, amount, (short) -1);
55+
}
56+
57+
public ItemStack(ItemType itemType, int amount, short durability) {
58+
this.itemType = itemType;
59+
this.amount = (byte) amount;
60+
this.durability = durability;
61+
}
62+
63+
@Override
64+
public boolean flagSet(ItemFlag flag) {
65+
return (this.hideFlags & (1 << flag.getBitIndex()))==1;
66+
}
67+
68+
@Override
69+
public void itemFlag(ItemFlag flag, boolean active) {
70+
if (active) {
71+
this.hideFlags |= (1 << flag.getBitIndex());
72+
} else {
73+
this.hideFlags &= ~(1 << flag.getBitIndex());
74+
}
75+
}
76+
77+
@Override
78+
public Set<ItemFlag> itemFlags() {
79+
Set<ItemFlag> flags = new HashSet<>();
80+
for (ItemFlag flag : ItemFlag.values()) {
81+
if (flagSet(flag)) {
82+
flags.add(flag);
83+
}
84+
}
85+
return Collections.unmodifiableSet(flags);
86+
}
87+
88+
@Override
89+
public boolean canBeStacked(ItemStack stack) {
90+
return stack.itemType()==this.itemType && stack.nbtData().equals(this.nbtData);
91+
}
92+
93+
@Override
94+
public <T> T displayName() {
95+
return displayName(false);
96+
}
97+
98+
@Override
99+
public <T> T displayName(boolean legacyString) {
100+
if (this.displayNameJson==null) {
101+
return null;
102+
}
103+
if (legacyString) {
104+
return (T) CONVERTER.toLegacyText(CONVERTER.fromJson(this.displayNameJson));
105+
} else {
106+
return (T) CONVERTER.fromJson(this.displayNameJson);
107+
}
108+
}
109+
110+
@Override
111+
public ItemStack displayName(String legacyName) {
112+
this.displayNameJson = CONVERTER.toJson(CONVERTER.fromLegacyText(legacyName));
113+
return this;
114+
}
115+
116+
@Override
117+
public ItemStack displayName(Object displayName) {
118+
this.displayNameJson = CONVERTER.toJson(displayName);
119+
return this;
120+
}
121+
122+
@Override
123+
public <T> List<T> lore() {
124+
return lore(false);
125+
}
126+
127+
@Override
128+
public <T> List<T> lore(boolean legacyString) {
129+
List<T> out = new ArrayList<>();
130+
for (String line : this.loreJson) {
131+
if (legacyString) {
132+
out.add((T) CONVERTER.toLegacyText(CONVERTER.fromJson(line)));
133+
} else {
134+
out.add((T) CONVERTER.fromJson(line));
135+
}
136+
}
137+
return out;
138+
}
139+
140+
@Override
141+
public void lore(List<?> list, boolean legacyString) {
142+
Preconditions.checkNotNull(list, "The lore list cannot be null.");
143+
List<String> out = new ArrayList<>();
144+
for (Object line : list) {
145+
if (legacyString) {
146+
out.add(CONVERTER.toJson(CONVERTER.fromLegacyText((String) line)));
147+
} else {
148+
out.add(CONVERTER.toJson(line));
149+
}
150+
}
151+
this.loreJson = out;
152+
}
153+
154+
@Override
155+
public void lore(int index, String legacyText) {
156+
this.loreJson.set(index, CONVERTER.toJson(CONVERTER.fromLegacyText(legacyText)));
157+
}
158+
159+
@Override
160+
public void lore(int index, Object component) {
161+
this.loreJson.set(index, CONVERTER.toJson(component));
162+
}
163+
164+
@Override
165+
public void addToLore(String legacyText) {
166+
this.loreJson.add(CONVERTER.toJson(CONVERTER.fromLegacyText(legacyText)));
167+
}
168+
169+
@Override
170+
public void addToLore(Object component) {
171+
this.loreJson.add(CONVERTER.toJson(component));
172+
}
173+
174+
@Override
175+
public ItemStack deepClone() {
176+
return deepClone(ProtocolVersions.MINECRAFT_LATEST);
177+
}
178+
179+
@Override
180+
public ItemStack deepClone(int protocolVersion) {
181+
ByteBuf buf = Unpooled.buffer();
182+
ItemStackSerializer.write(buf, this, protocolVersion);
183+
ItemStack itemStack = ItemStackSerializer.read(buf, protocolVersion);
184+
buf.release();
185+
return itemStack;
186+
}
169187

170188
}

0 commit comments

Comments
 (0)