Skip to content

Commit 3c3910b

Browse files
committed
v1.2.2 PUSH
1 parent ffd4999 commit 3c3910b

10 files changed

Lines changed: 339 additions & 159 deletions

File tree

src/main/java/de/timecoding/cc/command/CubicCommand.java

Lines changed: 186 additions & 114 deletions
Large diffs are not rendered by default.

src/main/java/de/timecoding/cc/event/CubeCountdownCancelEvent.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ public CubeCountdownCancelEvent(Player player, CountdownModule countdownModule)
2020
this.cubicSettings = this.countdownModule.getCubicSettings();
2121
}
2222

23-
public boolean whileAnimation(){
23+
public boolean whileFillAnimation(){
2424
if(cubicSettings.getCube() != null){
25-
return countdownModule.getPlugin().getCubicAPI().getAnimationList().containsKey(cubicSettings.getCube().getName());
25+
return countdownModule.getPlugin().getCubicAPI().getFillAnimationList().containsKey(cubicSettings.getCube().getName());
26+
}
27+
return false;
28+
}
29+
30+
public boolean whileClearAnimation(){
31+
if(cubicSettings.getCube() != null){
32+
return countdownModule.getPlugin().getCubicAPI().getClearAnimationList().containsKey(cubicSettings.getCube().getName());
2633
}
2734
return false;
2835
}

src/main/java/de/timecoding/cc/event/CubeCountdownStartEvent.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@ public CubeCountdownStartEvent(Player player, CountdownModule countdownModule) {
2020
this.cubicSettings = this.countdownModule.getCubicSettings();
2121
}
2222

23-
public boolean whileAnimation(){
23+
public boolean whileFillAnimation(){
2424
if(cubicSettings.getCube() != null){
25-
return countdownModule.getPlugin().getCubicAPI().getAnimationList().containsKey(cubicSettings.getCube().getName());
25+
return countdownModule.getPlugin().getCubicAPI().getFillAnimationList().containsKey(cubicSettings.getCube().getName());
26+
}
27+
return false;
28+
}
29+
30+
public boolean whileClearAnimation(){
31+
if(cubicSettings.getCube() != null){
32+
return countdownModule.getPlugin().getCubicAPI().getClearAnimationList().containsKey(cubicSettings.getCube().getName());
2633
}
2734
return false;
2835
}

src/main/java/de/timecoding/cc/file/ConfigHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class ConfigHandler {
1919

2020
private final CubicCountdown plugin;
21-
private final String newconfigversion = "1.2.1";
21+
private final String newconfigversion = "1.2.2";
2222
private final boolean retry = false;
2323
public YamlConfiguration cfg = null;
2424
private File f = null;

src/main/java/de/timecoding/cc/listener/CubicListener.java

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public CubicListener(CubicCountdown plugin) {
3535
@EventHandler
3636
public void onCubeCountdownEnd(CubeCountdownEndEvent event) {
3737
if (event.getCubicSettings().getCube() != null) {
38-
executeCommands("OnCountdownEnd", event.getCubicSettings().getCube().getName());
3938
plugin.getCubicAPI().increaseWins(event.getCubicSettings().getCube());
4039
}
4140
}
@@ -45,7 +44,7 @@ public void onCubeCountdownCancel(CubeCountdownCancelEvent event) {
4544
if (event.getCubicSettings().getCube() != null) {
4645
executeCommands("OnCountdownCancel", event.getCubicSettings().getCube().getName());
4746
plugin.getCubicAPI().increaseLoses(event.getCubicSettings().getCube());
48-
if(plugin.getConfigHandler().getBoolean("Reverse")){
47+
if(!plugin.getConfigHandler().getBoolean("Reverse") && event.whileFillAnimation() || plugin.getConfigHandler().getBoolean("Reverse") && event.whileClearAnimation()){
4948
plugin.getCubicAPI().increaseHelpCounter(event.getCubicSettings().getCube());
5049
}
5150
}
@@ -55,14 +54,17 @@ public void onCubeCountdownCancel(CubeCountdownCancelEvent event) {
5554
public void onCubeCountdownStart(CubeCountdownStartEvent event){
5655
if (event.getCubicSettings().getCube() != null) {
5756
executeCommands("OnCountdownStart", event.getCubicSettings().getCube().getName());
58-
if(!plugin.getConfigHandler().getBoolean("Reverse")){
57+
if(!plugin.getConfigHandler().getBoolean("Reverse") && event.whileFillAnimation() || plugin.getConfigHandler().getBoolean("Reverse") && event.whileClearAnimation()){
5958
plugin.getCubicAPI().increaseHelpCounter(event.getCubicSettings().getCube());
6059
}
6160
}
6261
}
6362

64-
private void executeCommands(String key, String map){
63+
public void executeCommands(String key, String map){
6564
plugin.getConfigHandler().getStringList("Commands."+key+"").forEach(command -> {
65+
if(command.startsWith(" ") || command.startsWith("/")){
66+
command = command.substring(0, command.length()-1);
67+
}
6668
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command.replaceAll("%map%", map));
6769
});
6870
}
@@ -184,30 +186,47 @@ public void run() {
184186
if (player != null && !cubicSettings.playerList().contains(player)) {
185187
cubicSettings.addPlayer(player);
186188
}
187-
CountdownModule countdownModule = new CountdownModule(cubicSettings);
188-
CubeCountdownStartEvent event = new CubeCountdownStartEvent(player, countdownModule);
189-
Bukkit.getPluginManager().callEvent(event);
190-
if (!event.isCancelled()) {
191-
countdownModule.start();
192-
r.set(true);
189+
if(atomicCube.get() != null && plugin.getCubicAPI().getCountdownModuleFromCube(atomicCube.get()) == null) {
190+
CountdownModule countdownModule = new CountdownModule(cubicSettings);
191+
CubeCountdownStartEvent event = new CubeCountdownStartEvent(player, countdownModule);
192+
Bukkit.getPluginManager().callEvent(event);
193+
if (!event.isCancelled()) {
194+
countdownModule.start();
195+
r.set(true);
196+
}
197+
if(plugin.getConfigHandler().getBoolean("Reverse") && plugin.getCubicAPI().getClearAnimationList().containsKey(atomicCube.get().getName())) {
198+
Bukkit.getScheduler().cancelTask(plugin.getCubicAPI().getClearAnimationList().get(atomicCube.get().getName()));
199+
plugin.getCubicAPI().getClearAnimationList().remove(atomicCube.get().getName());
200+
}else if(plugin.getCubicAPI().getFillAnimationList().containsKey(atomicCube.get().getName())){
201+
Bukkit.getScheduler().cancelTask(plugin.getCubicAPI().getFillAnimationList().get(atomicCube.get().getName()));
202+
plugin.getCubicAPI().getFillAnimationList().remove(atomicCube.get().getName());
203+
}
193204
}
194205
} else if (!reverse && atomicCube.get() != null && !atomicCube.get().filledOut() || reverse && atomicCube.get() != null && !atomicCube.get().empty()) {
195206
try {
196207
plugin.getCountdownList().forEach(countdownModule -> {
197208
if (countdownModule.getCubicSettings().getCube() != null && countdownModule.getCubicSettings().getCube().isSimilar(atomicCube.get())) {
198-
CubeCountdownCancelEvent event = new CubeCountdownCancelEvent(player, countdownModule);
199-
Bukkit.getPluginManager().callEvent(event);
200-
if (!event.isCancelled()) {
201-
countdownModule.cancel();
202-
r.set(true);
209+
if(atomicCube.get() != null && plugin.getCubicAPI().getCountdownModuleFromCube(atomicCube.get()) != null) {
210+
CubeCountdownCancelEvent event = new CubeCountdownCancelEvent(player, countdownModule);
211+
Bukkit.getPluginManager().callEvent(event);
212+
if (!event.isCancelled()) {
213+
countdownModule.cancel();
214+
r.set(true);
215+
}
216+
if(!plugin.getConfigHandler().getBoolean("Reverse") && plugin.getCubicAPI().getClearAnimationList().containsKey(atomicCube.get().getName())) {
217+
Bukkit.getScheduler().cancelTask(plugin.getCubicAPI().getClearAnimationList().get(atomicCube.get().getName()));
218+
plugin.getCubicAPI().getClearAnimationList().remove(atomicCube.get().getName());
219+
}else if(plugin.getCubicAPI().getFillAnimationList().containsKey(atomicCube.get().getName())){
220+
Bukkit.getScheduler().cancelTask(plugin.getCubicAPI().getFillAnimationList().get(atomicCube.get().getName()));
221+
plugin.getCubicAPI().getFillAnimationList().remove(atomicCube.get().getName());
222+
}
203223
}
204224
}
205225
});
206226
//TODO
207227
} catch (ConcurrentModificationException exception) {
208228
}
209229
}
210-
211230
}
212231
});
213232
}

src/main/java/de/timecoding/cc/util/CountdownModule.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,16 @@ public void run() {
6868
}
6969
sendTitle(plugin.getConfigHandler().getString(base + "Title").replace("%seconds%", String.valueOf(seconds)), subtitle);
7070
}
71-
if (Sound.valueOf(plugin.getConfigHandler().getString(base + "Sound")) != null) {
72-
playSound(Sound.valueOf(plugin.getConfigHandler().getString(base + "Sound")));
73-
}
74-
if (plugin.getConfigHandler().keyExists(base + "Ticks")) {
75-
extraTicks(base);
76-
}
71+
cubicSettings.playerList().forEach(player -> {
72+
if (plugin.getConfigHandler().getString(base+"Sound.Custom").equalsIgnoreCase("")) {
73+
player.playSound(player.getLocation(), Sound.valueOf(plugin.getConfigHandler().getString(base+"Sound.Sound")), (float) plugin.getConfigHandler().getConfig().getDouble(base+".Sound.Volume"), (float) plugin.getConfigHandler().getConfig().getDouble(base + ".Sound.Pitch"));
74+
}else{
75+
player.playSound(player.getLocation(), plugin.getConfigHandler().getString(base+"Sound.Custom"), (float) plugin.getConfigHandler().getConfig().getDouble(base+".Sound.Volume"), (float) plugin.getConfigHandler().getConfig().getDouble(base + ".Sound.Pitch"));
76+
}
77+
if (plugin.getConfigHandler().keyExists(base + "Ticks")) {
78+
extraTicks(base);
79+
}
80+
});
7781
} else {
7882
sendTitle(cubicSettings.getTitle(CubicStateType.PROCEED).replace("%seconds%", String.valueOf(seconds)), cubicSettings.getSubtitle(CubicStateType.PROCEED));
7983
playSound(CubicStateType.PROCEED);
@@ -90,6 +94,7 @@ public void run() {
9094
firework.detonate();
9195
});
9296
clearCube();
97+
plugin.getCubicListener().executeCommands("OnCountdownEnd", event.getCubicSettings().getCube().getName());
9398
stop();
9499
}
95100
}
@@ -113,7 +118,11 @@ private void sendTitle(CubicStateType cubicStateType) {
113118
private void playSound(CubicStateType cubicStateType) {
114119
cubicSettings.playerList().forEach(player -> {
115120
if (cubicSettings.hasSound(cubicStateType)) {
116-
player.playSound(player.getLocation(), cubicSettings.getSound(cubicStateType), 2, 2);
121+
if (plugin.getConfigHandler().getString("Settings." + cubicStateType.toString().toUpperCase() + ".Sound.Custom").equalsIgnoreCase("")) {
122+
player.playSound(player.getLocation(), cubicSettings.getSound(cubicStateType), (float) plugin.getConfigHandler().getConfig().getDouble("Settings." + cubicStateType.toString().toUpperCase() + ".Sound.Volume"), (float) plugin.getConfigHandler().getConfig().getDouble("Settings." + cubicStateType.toString().toUpperCase() + ".Sound.Pitch"));
123+
}else{
124+
player.playSound(player.getLocation(), plugin.getConfigHandler().getString("Settings." + cubicStateType.toString().toUpperCase() + ".Sound.Custom"), (float) plugin.getConfigHandler().getConfig().getDouble("Settings." + cubicStateType.toString().toUpperCase() + ".Sound.Volume"), (float) plugin.getConfigHandler().getConfig().getDouble("Settings." + cubicStateType.toString().toUpperCase() + ".Sound.Pitch"));
125+
}
117126
}
118127
});
119128
}

src/main/java/de/timecoding/cc/util/CubicAPI.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public class CubicAPI {
2222
private List<CountdownModule> countdownList = new ArrayList<>();
2323
private HashMap<Player, CubicSetup> setupList = new HashMap<>();
2424

25-
private HashMap<String, Integer> animationList = new HashMap<>();
25+
private HashMap<String, Integer> fillAnimationList = new HashMap<>();
26+
private HashMap<String, Integer> clearAnimationList = new HashMap<>();
2627
private int actionRunnable = -1;
2728

2829
public CubicAPI(CubicCountdown plugin) {
@@ -68,8 +69,12 @@ private boolean actionbarRunning() {
6869
return (actionRunnable != -1);
6970
}
7071

71-
public HashMap<String, Integer> getAnimationList() {
72-
return animationList;
72+
public HashMap<String, Integer> getFillAnimationList() {
73+
return fillAnimationList;
74+
}
75+
76+
public HashMap<String, Integer> getClearAnimationList() {
77+
return clearAnimationList;
7378
}
7479

7580
public String replaceWithPlaceholders(Cube cube, String title){
@@ -236,7 +241,6 @@ public void increaseSessionWins(Cube cube) {
236241
Integer integer = 1;
237242
if (session_wins.containsKey(cube.getName())) {
238243
integer = session_wins.get(cube.getName())+1;
239-
session_wins.put(cube.getName(), (session_wins.get(cube.getName())+1));
240244
}
241245
session_wins.put(cube.getName(), (integer));
242246
}
@@ -256,7 +260,6 @@ public void increaseSessionHelps(Cube cube) {
256260
Integer integer = 1;
257261
if (session_helps.containsKey(cube.getName())) {
258262
integer = session_helps.get(cube.getName())+1;
259-
session_helps.put(cube.getName(), (session_helps.get(cube.getName())+1));
260263
}
261264
session_helps.put(cube.getName(), (integer));
262265
}
@@ -276,7 +279,6 @@ public void increaseSessionLoses(Cube cube) {
276279
Integer integer = 1;
277280
if (session_loses.containsKey(cube.getName())) {
278281
integer = session_loses.get(cube.getName())+1;
279-
session_loses.put(cube.getName(), (session_loses.get(cube.getName())+1));
280282
}
281283
session_loses.put(cube.getName(), (integer));
282284
}

src/main/java/de/timecoding/cc/util/CubicSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public CubicSettings(CubicCountdown plugin, boolean fromConfig) {
4141
Arrays.stream(CubicStateType.values()).forEach(cubicStateType -> {
4242
setTitle(cubicStateType, configHandler.getString("Settings." + cubicStateType.toString().toUpperCase() + ".Title"));
4343
setSubtitle(cubicStateType, configHandler.getString("Settings." + cubicStateType.toString().toUpperCase() + ".Subtitle"));
44-
String soundString = configHandler.getString("Settings." + cubicStateType.toString().toUpperCase() + ".Sound");
44+
String soundString = configHandler.getString("Settings." + cubicStateType.toString().toUpperCase() + ".Sound.Sound");
4545
Sound sound = getSoundFromString(soundString);
4646
if (sound != null) {
4747
setSound(cubicStateType, sound);

0 commit comments

Comments
 (0)