Skip to content

Commit 201091c

Browse files
committed
cosmetic基盤完成
1 parent 4994ddb commit 201091c

File tree

15 files changed

+233
-202
lines changed

15 files changed

+233
-202
lines changed

pom.xml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -82,19 +82,6 @@
8282
<version>1.19.2-R0.1-SNAPSHOT</version>
8383
<scope>provided</scope>
8484
</dependency>
85-
<dependency>
86-
<groupId>org.spigotmc</groupId>
87-
<artifactId>spigot</artifactId>
88-
<version>1.19.2-R0.1-SNAPSHOT</version>
89-
<scope>provided</scope>
90-
</dependency>
91-
<dependency>
92-
<groupId>net.md-5</groupId>
93-
<artifactId>bungeecord-api</artifactId>
94-
<version>1.19-R0.1-SNAPSHOT</version>
95-
<type>jar</type>
96-
<scope>provided</scope>
97-
</dependency>
9885
<dependency>
9986
<groupId>fr.mrmicky</groupId>
10087
<artifactId>fastboard</artifactId>
@@ -139,11 +126,27 @@
139126
<artifactId>annotations</artifactId>
140127
<version>23.0.0</version>
141128
</dependency>
129+
<dependency>
130+
<groupId>dev.dejvokep</groupId>
131+
<artifactId>boosted-yaml</artifactId>
132+
<version>1.3</version>
133+
</dependency>
142134
<dependency>
143135
<groupId>net.william278</groupId>
144136
<artifactId>Annotaml</artifactId>
145137
<version>2.0.1</version>
146138
<scope>compile</scope>
147139
</dependency>
140+
<dependency>
141+
<groupId>me.clip</groupId>
142+
<artifactId>placeholderapi</artifactId>
143+
<version>2.11.2</version>
144+
<scope>provided</scope>
145+
</dependency>
146+
<dependency>
147+
<groupId>xyz.xenondevs</groupId>
148+
<artifactId>particle</artifactId>
149+
<version>1.8.1</version>
150+
</dependency>
148151
</dependencies>
149152
</project>

src/main/java/com/github/elic0de/thejpspit/TheJpsPit.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,27 @@
77
import com.github.elic0de.thejpspit.command.SpawnCommand;
88
import com.github.elic0de.thejpspit.config.PitPreferences;
99
import com.github.elic0de.thejpspit.config.Settings;
10+
import com.github.elic0de.thejpspit.cosmetics.CosmeticManager;
1011
import com.github.elic0de.thejpspit.database.Database;
1112
import com.github.elic0de.thejpspit.database.SqLiteDatabase;
12-
import com.github.elic0de.thejpspit.hook.PlaceholderHook;
13-
import com.github.elic0de.thejpspit.leveler.Levels;
14-
import com.github.elic0de.thejpspit.listener.CombatTagger;
15-
import com.github.elic0de.thejpspit.player.PitPlayer;
16-
import com.github.elic0de.thejpspit.player.PitPlayerManager;
1713
import com.github.elic0de.thejpspit.game.Game;
1814
import com.github.elic0de.thejpspit.hook.EconomyHook;
1915
import com.github.elic0de.thejpspit.hook.Hook;
16+
import com.github.elic0de.thejpspit.hook.PlaceholderHook;
2017
import com.github.elic0de.thejpspit.hook.VaultEconomyHook;
2118
import com.github.elic0de.thejpspit.item.ItemManager;
19+
import com.github.elic0de.thejpspit.leveler.Levels;
2220
import com.github.elic0de.thejpspit.listener.BlockPlaceListener;
21+
import com.github.elic0de.thejpspit.listener.CombatTagger;
2322
import com.github.elic0de.thejpspit.listener.EventListener;
23+
import com.github.elic0de.thejpspit.player.PitPlayer;
24+
import com.github.elic0de.thejpspit.player.PitPlayerManager;
2425
import com.github.elic0de.thejpspit.util.KillAssistHelper;
2526
import com.github.elic0de.thejpspit.util.KillRatingHelper;
2627
import com.github.elic0de.thejpspit.villager.VillagerNPCManager;
2728
import com.github.elic0de.thejpspit.villager.villagers.ShopVillager;
2829
import com.google.gson.Gson;
2930
import com.google.gson.GsonBuilder;
30-
import me.clip.placeholderapi.configuration.PlaceholderAPIConfig;
31-
import net.william278.annotaml.Annotaml;
32-
import org.bukkit.Bukkit;
33-
import org.bukkit.GameRule;
34-
import org.bukkit.plugin.PluginManager;
35-
import org.bukkit.plugin.java.JavaPlugin;
36-
3731
import java.io.File;
3832
import java.io.IOException;
3933
import java.lang.reflect.InvocationTargetException;
@@ -42,6 +36,11 @@
4236
import java.util.Optional;
4337
import java.util.concurrent.atomic.AtomicBoolean;
4438
import java.util.logging.Level;
39+
import net.william278.annotaml.Annotaml;
40+
import org.bukkit.Bukkit;
41+
import org.bukkit.GameRule;
42+
import org.bukkit.plugin.PluginManager;
43+
import org.bukkit.plugin.java.JavaPlugin;
4544

4645
public final class TheJpsPit extends JavaPlugin {
4746

@@ -56,6 +55,8 @@ public final class TheJpsPit extends JavaPlugin {
5655

5756
private Optional<PitPreferences> pitPreferences;
5857

58+
private CosmeticManager cosmeticManager;
59+
5960
public static TheJpsPit getInstance() {
6061
return instance;
6162
}
@@ -100,6 +101,7 @@ public void onEnable() {
100101
"Please check the supplied database credentials in the config file");
101102
}
102103

104+
cosmeticManager = new CosmeticManager();
103105
assistKillHelper = new KillAssistHelper();
104106
ratingHelper = new KillRatingHelper(0);
105107

@@ -112,14 +114,14 @@ public void onEnable() {
112114

113115
loadHooks();
114116

117+
ItemManager.createItems();
118+
createNPCs();
119+
115120
Bukkit.getWorlds().forEach(world -> {
116121
world.setGameRule(GameRule.DO_IMMEDIATE_RESPAWN, true);
117122
world.setGameRule(GameRule.KEEP_INVENTORY, true);
118123
});
119124

120-
ItemManager.createItems();
121-
createNPCs();
122-
123125
Bukkit.getOnlinePlayers().forEach(player -> {
124126
final Optional<PitPlayer> userData = database.getPitPlayer(player);
125127
if (userData.isEmpty()) {
@@ -264,6 +266,9 @@ public Optional<PitPreferences> getPitPreferences() {
264266
return pitPreferences;
265267
}
266268

269+
public CosmeticManager getCosmeticManager() {
270+
return cosmeticManager;
271+
}
267272

268273
public Gson getGson() {
269274
return Converters.registerOffsetDateTime(new GsonBuilder().excludeFieldsWithoutExposeAnnotation()).create();
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.github.elic0de.thejpspit.cosmetics;
2+
3+
public interface AbstractCosmetic {
4+
5+
String getId();
6+
7+
String getName();
8+
9+
String getDescription();
10+
11+
double getCoin();
12+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.github.elic0de.thejpspit.cosmetics;
2+
3+
import com.github.elic0de.thejpspit.player.PitPlayer;
4+
import java.util.concurrent.atomic.AtomicBoolean;
5+
6+
public class Cosmetic implements AbstractCosmetic {
7+
8+
9+
private String cosmeticId;
10+
private String cosmeticName;
11+
12+
private String cosmeticDescription;
13+
14+
private double coin;
15+
16+
public Cosmetic() {
17+
final Class<?> cosmeticClass = this.getClass();
18+
19+
if (cosmeticClass.isAnnotationPresent(CosmeticData.class)) {
20+
final CosmeticData cosmeticData = cosmeticClass.getAnnotation(CosmeticData.class);
21+
this.cosmeticId = cosmeticData.id();
22+
this.cosmeticName = cosmeticData.name();
23+
this.cosmeticDescription = cosmeticData.description();
24+
this.coin = cosmeticData.coin();
25+
}
26+
}
27+
28+
public final boolean canExecute(PitPlayer player) {
29+
final AtomicBoolean canExecute = new AtomicBoolean(false);
30+
player.getPreferences().ifPresent(preferences -> canExecute.set(preferences.getCosmeticsCollection().isSelectedCosmetic(cosmeticId)));
31+
32+
return canExecute.get();
33+
}
34+
35+
public String getId() {
36+
return cosmeticId;
37+
}
38+
39+
public String getName() {
40+
return cosmeticName;
41+
}
42+
43+
public String getDescription() {
44+
return cosmeticDescription;
45+
}
46+
47+
public double getCoin() {
48+
return coin;
49+
}
50+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.github.elic0de.thejpspit.cosmetics;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
@Retention(RetentionPolicy.RUNTIME)
9+
@Target(ElementType.TYPE)
10+
public @interface CosmeticData {
11+
String id() default "";
12+
13+
String name() default "UNKNOWN";
14+
15+
String description() default "No description provided";
16+
17+
double coin() default 0;
18+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.github.elic0de.thejpspit.cosmetics;
2+
3+
import com.github.elic0de.thejpspit.cosmetics.impl.kill.FireCosmetic;
4+
import com.github.elic0de.thejpspit.cosmetics.type.KillCosmetic;
5+
import com.github.elic0de.thejpspit.player.PitPlayer;
6+
import com.google.common.collect.ClassToInstanceMap;
7+
import com.google.common.collect.ImmutableClassToInstanceMap;
8+
9+
public class CosmeticManager {
10+
11+
ClassToInstanceMap<KillCosmetic> killCosmetics;
12+
13+
public CosmeticManager() {
14+
killCosmetics = new ImmutableClassToInstanceMap.Builder<KillCosmetic>()
15+
.put(FireCosmetic.class, new FireCosmetic())
16+
.build();
17+
}
18+
19+
public void onProcess(PitPlayer player) {
20+
for (KillCosmetic cosmetic : killCosmetics.values()) {
21+
cosmetic.onKill(player);
22+
}
23+
}
24+
25+
public ClassToInstanceMap<KillCosmetic> getKillCosmetics() {
26+
return killCosmetics;
27+
}
28+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.github.elic0de.thejpspit.cosmetics.impl.kill;
2+
3+
import com.github.elic0de.thejpspit.cosmetics.Cosmetic;
4+
import com.github.elic0de.thejpspit.cosmetics.CosmeticData;
5+
import com.github.elic0de.thejpspit.cosmetics.type.KillCosmetic;
6+
import com.github.elic0de.thejpspit.player.PitPlayer;
7+
import xyz.xenondevs.particle.ParticleBuilder;
8+
import xyz.xenondevs.particle.ParticleEffect;
9+
10+
@CosmeticData(id = "Fire", name = "ファイやー", coin = 50)
11+
public class FireCosmetic extends Cosmetic implements KillCosmetic {
12+
13+
@Override
14+
public void onKill(PitPlayer player) {
15+
if (canExecute(player)) {
16+
new ParticleBuilder(ParticleEffect.FLAME, player.getPlayer().getLocation())
17+
.setOffsetY(1f)
18+
.setSpeed(0.1f)
19+
.display();
20+
}
21+
}
22+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.github.elic0de.thejpspit.cosmetics.type;
2+
3+
import com.github.elic0de.thejpspit.cosmetics.AbstractCosmetic;
4+
import com.github.elic0de.thejpspit.player.PitPlayer;
5+
6+
public interface KillCosmetic extends AbstractCosmetic {
7+
8+
default void onKill(PitPlayer player) {
9+
}
10+
}

src/main/java/com/github/elic0de/thejpspit/game/Game.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public void death(PitPlayer player) {
9999
);
100100
}
101101
});
102+
pit.getCosmeticManager().onProcess(player);
102103

103104
player.setLastDamager(null);
104105
pit.getDatabase().updateUserData(player);

src/main/java/com/github/elic0de/thejpspit/player/Preferences.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.google.gson.annotations.Expose;
44
import com.google.gson.annotations.SerializedName;
5+
import java.util.List;
56

67
public class Preferences {
78

@@ -17,16 +18,25 @@ public class Preferences {
1718
@SerializedName("streaks_message")
1819
private boolean streaksMessage;
1920

21+
@Expose
22+
@SerializedName("cosmeticsCollection")
23+
private final PurchasedCosmeticsCollection cosmeticsCollection;
24+
2025
public Preferences() {
2126
this.killMessage = true;
2227
this.deathMessage = true;
2328
this.streaksMessage = true;
29+
this.cosmeticsCollection = new PurchasedCosmeticsCollection();
2430
}
2531

2632
public static Preferences getDefaults() {
2733
return new Preferences();
2834
}
2935

36+
public PurchasedCosmeticsCollection getCosmeticsCollection() {
37+
return cosmeticsCollection;
38+
}
39+
3040
public boolean isKillMessage() {
3141
return killMessage;
3242
}

0 commit comments

Comments
 (0)