Skip to content

Commit f697999

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents dd6abc4 + 44ebf24 commit f697999

File tree

10 files changed

+144
-22
lines changed

10 files changed

+144
-22
lines changed

src/main/java/com/github/elic0de/thejpspit/cosmetics/CosmeticManager.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@
55
import com.github.elic0de.thejpspit.cosmetics.impl.death.LightingDeathCosmetic;
66
import com.github.elic0de.thejpspit.cosmetics.impl.kill.BloodKillCosmetic;
77
import com.github.elic0de.thejpspit.cosmetics.impl.kill.FireCosmetic;
8+
import com.github.elic0de.thejpspit.cosmetics.impl.trail.GreenStar;
9+
import com.github.elic0de.thejpspit.cosmetics.type.AuraCosmetic;
810
import com.github.elic0de.thejpspit.cosmetics.type.DeathCosmetic;
911
import com.github.elic0de.thejpspit.cosmetics.type.KillCosmetic;
12+
import com.github.elic0de.thejpspit.cosmetics.type.StreakCosmetic;
13+
import com.github.elic0de.thejpspit.cosmetics.type.TrailCosmetic;
1014
import com.github.elic0de.thejpspit.player.PitPlayer;
1115
import com.google.common.collect.ClassToInstanceMap;
1216
import com.google.common.collect.ImmutableClassToInstanceMap;
17+
import org.bukkit.entity.Entity;
1318

1419
public class CosmeticManager {
1520

1621
ClassToInstanceMap<KillCosmetic> killCosmetics;
1722
ClassToInstanceMap<DeathCosmetic> deathCosmetics;
23+
ClassToInstanceMap<StreakCosmetic> streakCosmetics;
24+
ClassToInstanceMap<TrailCosmetic> trailCosmetics;
25+
ClassToInstanceMap<AuraCosmetic> auraCosmetics;
26+
1827

1928
public ClassToInstanceMap<AbstractCosmetic> allCosmetics;
2029

@@ -30,9 +39,22 @@ public CosmeticManager() {
3039
.put(LightingDeathCosmetic.class, new LightingDeathCosmetic())
3140
.build();
3241

42+
streakCosmetics = new ImmutableClassToInstanceMap.Builder<StreakCosmetic>()
43+
.build();
44+
45+
trailCosmetics = new ImmutableClassToInstanceMap.Builder<TrailCosmetic>()
46+
.put(GreenStar.class, new GreenStar())
47+
.build();
48+
49+
auraCosmetics = new ImmutableClassToInstanceMap.Builder<AuraCosmetic>()
50+
.build();
51+
3352
allCosmetics = new ImmutableClassToInstanceMap.Builder<AbstractCosmetic>()
3453
.putAll(killCosmetics)
3554
.putAll(deathCosmetics)
55+
.putAll(streakCosmetics)
56+
.putAll(trailCosmetics)
57+
.putAll(auraCosmetics)
3658
.build();
3759
}
3860

@@ -48,6 +70,24 @@ public void onDeath(PitPlayer player) {
4870
}
4971
}
5072

73+
public void onStreak(PitPlayer player) {
74+
for (StreakCosmetic cosmetic : streakCosmetics.values()) {
75+
cosmetic.onStreak(player);
76+
}
77+
}
78+
79+
public void onTrail(PitPlayer player, Entity target) {
80+
for (TrailCosmetic cosmetic : trailCosmetics.values()) {
81+
cosmetic.onTrail(player, target);
82+
}
83+
}
84+
85+
public void onAura(PitPlayer player) {
86+
for (AuraCosmetic cosmetic : auraCosmetics.values()) {
87+
cosmetic.onAura(player);
88+
}
89+
}
90+
5191
public ClassToInstanceMap<KillCosmetic> getKillCosmetics() {
5292
return killCosmetics;
5393
}
@@ -56,6 +96,18 @@ public ClassToInstanceMap<DeathCosmetic> getDeathCosmetics() {
5696
return deathCosmetics;
5797
}
5898

99+
public ClassToInstanceMap<StreakCosmetic> getStreakCosmetics() {
100+
return streakCosmetics;
101+
}
102+
103+
public ClassToInstanceMap<TrailCosmetic> getTrailCosmetics() {
104+
return trailCosmetics;
105+
}
106+
107+
public ClassToInstanceMap<AuraCosmetic> getAuraCosmetics() {
108+
return auraCosmetics;
109+
}
110+
59111
public ClassToInstanceMap<AbstractCosmetic> getAllCosmetics() {
60112
return allCosmetics;
61113
}

src/main/java/com/github/elic0de/thejpspit/cosmetics/impl/death/BloodDeathCosmetic.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.github.elic0de.thejpspit.cosmetics.CosmeticData;
55
import com.github.elic0de.thejpspit.cosmetics.type.DeathCosmetic;
66
import com.github.elic0de.thejpspit.player.PitPlayer;
7+
import org.bukkit.Effect;
78
import org.bukkit.Material;
89
import xyz.xenondevs.particle.ParticleBuilder;
910
import xyz.xenondevs.particle.ParticleEffect;
@@ -14,10 +15,8 @@ public class BloodDeathCosmetic extends Cosmetic implements DeathCosmetic {
1415
@Override
1516
public void onDeath(PitPlayer player) {
1617
if (canExecute(player)) {
17-
new ParticleBuilder(ParticleEffect.REDSTONE, player.getPlayer().getLocation())
18-
.setAmount(15)
19-
.setOffsetY(1f)
20-
.setSpeed(0.1f)
21-
.display(); }
18+
player.getPlayer().playEffect(player.getPlayer().getLocation().clone().add(0, 0.5, 0), Effect.STEP_SOUND, 152);
19+
player.getPlayer().playEffect(player.getPlayer().getLocation().clone().add(0, 1, 0), Effect.STEP_SOUND, 152);
20+
}
2221
}
2322
}

src/main/java/com/github/elic0de/thejpspit/cosmetics/impl/kill/BloodKillCosmetic.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@
44
import com.github.elic0de.thejpspit.cosmetics.CosmeticData;
55
import com.github.elic0de.thejpspit.cosmetics.type.KillCosmetic;
66
import com.github.elic0de.thejpspit.player.PitPlayer;
7+
import org.bukkit.Effect;
78
import org.bukkit.Material;
8-
import xyz.xenondevs.particle.ParticleBuilder;
9-
import xyz.xenondevs.particle.ParticleEffect;
109

1110
@CosmeticData(id = "bloodkill", name = "あか", description = "あかかかかk", icon = Material.RED_DYE, coin = 50)
1211
public class BloodKillCosmetic extends Cosmetic implements KillCosmetic {
1312

1413
@Override
1514
public void onKill(PitPlayer player, PitPlayer target) {
1615
if (canExecute(player)) {
17-
new ParticleBuilder(ParticleEffect.REDSTONE, target.getPlayer().getLocation())
18-
.setAmount(15)
19-
.setOffsetY(1f)
20-
.setSpeed(0.1f)
21-
.display();
16+
player.getPlayer().playEffect(player.getPlayer().getLocation().clone().add(0, 0.5, 0), Effect.STEP_SOUND, 152);
17+
player.getPlayer().playEffect(player.getPlayer().getLocation().clone().add(0, 1, 0), Effect.STEP_SOUND, 152);
2218
}
2319
}
24-
}
25-
20+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.github.elic0de.thejpspit.cosmetics.impl.trail;
2+
3+
import com.github.elic0de.thejpspit.TheJpsPit;
4+
import com.github.elic0de.thejpspit.cosmetics.Cosmetic;
5+
import com.github.elic0de.thejpspit.cosmetics.CosmeticData;
6+
import com.github.elic0de.thejpspit.cosmetics.type.TrailCosmetic;
7+
import com.github.elic0de.thejpspit.player.PitPlayer;
8+
import org.bukkit.Material;
9+
import org.bukkit.entity.Entity;
10+
import org.bukkit.scheduler.BukkitRunnable;
11+
import xyz.xenondevs.particle.ParticleEffect;
12+
13+
@CosmeticData(id = "greenstar", name = "なんか緑", description = "みどり", icon = Material.EMERALD, coin = 50)
14+
public class GreenStar extends Cosmetic implements TrailCosmetic {
15+
16+
@Override
17+
public void onTrail(PitPlayer player, Entity target) {
18+
if (canExecute(player)) {
19+
BukkitRunnable runnable = new BukkitRunnable() {
20+
@Override
21+
public void run() {
22+
if (target == null || target.isOnGround() || target.isDead()) {
23+
cancel();
24+
}
25+
ParticleEffect.VILLAGER_HAPPY.display(target.getLocation());
26+
}
27+
};
28+
runnable.runTaskTimer(TheJpsPit.getInstance(), 2, 2);
29+
}
30+
}
31+
}

src/main/java/com/github/elic0de/thejpspit/cosmetics/type/TrailCosmetic.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import com.github.elic0de.thejpspit.cosmetics.AbstractCosmetic;
44
import com.github.elic0de.thejpspit.player.PitPlayer;
5+
import org.bukkit.entity.Entity;
56

67
public interface TrailCosmetic extends AbstractCosmetic {
78

8-
default void onTrail(PitPlayer player) {
9+
default void onTrail(PitPlayer player, Entity target) {
910
}
1011
}

src/main/java/com/github/elic0de/thejpspit/gui/CosmeticsMenu.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private DynamicGuiElement getItemElement(AbstractCosmetic cosmetic) {
8181
final PurchasedCosmeticsCollection cosmeticsCollection = preferences.getCosmeticsCollection();
8282
if (hasCosmetic.get()) {
8383
if (isSelected.get()) {
84-
cosmeticsCollection.unSelectCosmetic();
84+
cosmeticsCollection.unSelectCosmetic(cosmetic);
8585
return;
8686
}
8787
cosmeticsCollection.selectCosmetic(cosmetic);

src/main/java/com/github/elic0de/thejpspit/listener/EventListener.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.bukkit.entity.Arrow;
2020
import org.bukkit.entity.Entity;
2121
import org.bukkit.entity.Player;
22+
import org.bukkit.entity.Projectile;
2223
import org.bukkit.entity.Villager;
2324
import org.bukkit.event.EventHandler;
2425
import org.bukkit.event.Listener;
@@ -29,6 +30,7 @@
2930
import org.bukkit.event.entity.EntityRegainHealthEvent;
3031
import org.bukkit.event.entity.FoodLevelChangeEvent;
3132
import org.bukkit.event.entity.PlayerDeathEvent;
33+
import org.bukkit.event.entity.ProjectileLaunchEvent;
3234
import org.bukkit.event.player.PlayerDropItemEvent;
3335
import org.bukkit.event.player.PlayerExpChangeEvent;
3436
import org.bukkit.event.player.PlayerInteractEntityEvent;
@@ -176,6 +178,15 @@ private void onEntityRegainHealth(EntityRegainHealthEvent event) {
176178
}
177179
}
178180

181+
@EventHandler
182+
public void onProjectileShoot(ProjectileLaunchEvent event) {
183+
Projectile target = event.getEntity();
184+
if (target.getShooter() instanceof Player player) {
185+
final PitPlayer pitPlayer = PitPlayerManager.getPitPlayer(player);
186+
TheJpsPit.getInstance().getCosmeticManager().onTrail(pitPlayer, target);
187+
}
188+
}
189+
179190
@EventHandler
180191
public void onXpGain(PlayerExpChangeEvent event) {
181192
event.setAmount(0);

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ public void increaseKills() {
244244
public void increaseStreaks() {
245245
this.streaks ++;
246246

247-
if (streaks % 5 == 0) TheJpsPit.getInstance().getGame().streakBroadcast(player.getName() + "&aが連続で&c" + streaks + "&aキルしています!" );
247+
if (streaks % 5 == 0) {
248+
TheJpsPit.getInstance().getCosmeticManager().onStreak(this);
249+
TheJpsPit.getInstance().getGame().streakBroadcast(player.getName() + "&aが連続で&c" + streaks + "&aキルしています!" );
250+
}
248251

249252
if (bestStreaks < streaks) {
250253
this.bestStreaks = streaks;

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

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33
import com.github.elic0de.thejpspit.TheJpsPit;
44
import com.github.elic0de.thejpspit.cosmetics.AbstractCosmetic;
55
import com.github.elic0de.thejpspit.cosmetics.Cosmetic;
6+
import com.github.elic0de.thejpspit.cosmetics.type.AuraCosmetic;
7+
import com.github.elic0de.thejpspit.cosmetics.type.DeathCosmetic;
8+
import com.github.elic0de.thejpspit.cosmetics.type.KillCosmetic;
9+
import com.github.elic0de.thejpspit.cosmetics.type.StreakCosmetic;
10+
import com.github.elic0de.thejpspit.cosmetics.type.TrailCosmetic;
611
import com.github.elic0de.thejpspit.hook.EconomyHook;
712
import com.google.gson.annotations.Expose;
813
import com.google.gson.annotations.SerializedName;
914
import java.math.BigDecimal;
15+
import java.util.HashMap;
1016
import java.util.HashSet;
17+
import java.util.Map;
1118
import java.util.Optional;
1219
import java.util.Set;
1320
import java.util.concurrent.atomic.AtomicBoolean;
@@ -23,18 +30,29 @@ public class PurchasedCosmeticsCollection {
2330

2431
@Expose
2532
@SerializedName("selected_id")
26-
private String selectedCosmeticId = "";
33+
private Map<String, String> selectedCosmeticId = new HashMap<>();
2734

35+
36+
37+
// todo:もっといいやりかたがあるはずなので教えてください
2838
public void selectCosmetic(AbstractCosmetic cosmetic) {
29-
this.selectedCosmeticId = cosmetic.getId();
39+
final String key = getKey(cosmetic);
40+
if (key == null) return;
41+
this.selectedCosmeticId.put(key, cosmetic.getId());
3042
}
3143

32-
public void unSelectCosmetic() {
33-
this.selectedCosmeticId = "";
44+
public void unSelectCosmetic(AbstractCosmetic cosmetic) {
45+
final String key = getKey(cosmetic);
46+
selectedCosmeticId.put(key, "");
47+
//this.selectedCosmeticId.containsValue()
3448
}
3549

3650
public boolean isSelectedCosmetic(AbstractCosmetic cosmetic) {
37-
return this.selectedCosmeticId.equals(cosmetic.getId());
51+
final String key = getKey(cosmetic);
52+
if (key == null) return false;
53+
if (selectedCosmeticId.containsKey(key))
54+
return this.selectedCosmeticId.get(key) == cosmetic.getId();
55+
return false;
3856
}
3957

4058
public boolean canBuy(PitPlayer pitPlayer, AbstractCosmetic cosmetic){
@@ -52,4 +70,14 @@ public boolean has(AbstractCosmetic cosmetic){
5270
return cosmeticsId.contains(cosmetic.getId());
5371
}
5472

73+
74+
private String getKey(AbstractCosmetic cosmetic) {
75+
String key = null;
76+
if (cosmetic instanceof KillCosmetic) key = "kill";
77+
if (cosmetic instanceof DeathCosmetic) key = "death";
78+
if (cosmetic instanceof StreakCosmetic) key = "streak";
79+
if (cosmetic instanceof TrailCosmetic) key = "trail";
80+
if (cosmetic instanceof AuraCosmetic) key = "aura";
81+
return key;
82+
}
5583
}

src/main/java/com/github/elic0de/thejpspit/task/GameTask.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ public GameTask() {
2626
@Override
2727
public void run() {
2828
pit.getGame().getScoreboard().update();
29+
2930
/*repeats.getAndIncrement();
3031
if (repeats.get() >= 5) {
3132
pit.getGame().getPitPlayers().forEach(PitPlayer::increaseHealth);
3233
repeats.set(0);
3334
}*/
3435
// TODO クラス分ける
3536
for (PitPlayer pitPlayer : pit.getGame().getPitPlayers()) {
37+
TheJpsPit.getInstance().getCosmeticManager().onAura(pitPlayer);
3638
final long streaks = pitPlayer.getStreaks();
3739
if (streaks < 5) continue;
3840
final Player player = pitPlayer.getPlayer();

0 commit comments

Comments
 (0)