Skip to content

Commit 1333296

Browse files
committed
v1.1 Update
1 parent ce0d740 commit 1333296

File tree

12 files changed

+1270
-88
lines changed

12 files changed

+1270
-88
lines changed

.idea/libraries/PlaceholderAPI_2_11_3.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/de/timecoding/cc/CubicCountdown.java

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package de.timecoding.cc;
22

3+
import de.timecoding.cc.api.CubicExpansion;
4+
import de.timecoding.cc.api.Metrics;
35
import de.timecoding.cc.command.CubicCommand;
46
import de.timecoding.cc.command.completer.CubicCompleter;
57
import de.timecoding.cc.command.setup.CubicSetup;
@@ -16,6 +18,7 @@
1618
import java.util.ArrayList;
1719
import java.util.HashMap;
1820
import java.util.List;
21+
import java.util.concurrent.atomic.AtomicBoolean;
1922
import java.util.concurrent.atomic.AtomicReference;
2023

2124
public class CubicCountdown extends JavaPlugin {
@@ -27,6 +30,7 @@ public class CubicCountdown extends JavaPlugin {
2730

2831
//FOR API USAGE ONLY
2932
private CubicCountdown plugin;
33+
private Metrics metrics = null;
3034

3135
public void onEnable() {
3236
this.plugin = this;
@@ -38,6 +42,20 @@ public void onEnable() {
3842
pluginCommand.setTabCompleter(new CubicCompleter(this));
3943
Bukkit.getConsoleSender().sendMessage("§cCubicCountdown §7(v" + this.getDescription().getVersion() + ") §aby §eTimeCode §awas enabled!");
4044
Bukkit.getConsoleSender().sendMessage("§cTHIS IS A BETA VERSION OF THE PLUGIN! PLEASE REPORT ALL ISSUES OR WISHES TO OUR DISCORD: https://discord.tikmc.de/");
45+
if(Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")){
46+
Bukkit.getConsoleSender().sendMessage("§aSuccessfully registered the CubicCountdown §ePlaceholderAPI Expansion§a!");
47+
new CubicExpansion(this).register();
48+
}
49+
if(!configHandler.keyExists("bStats") || configHandler.getBoolean("bStats")){
50+
this.metrics = new Metrics(this, 19676);
51+
}
52+
for(String key : plugin.getDataHandler().getConfig().getKeys(true)){
53+
if(key.endsWith("Wins") || key.endsWith("Loses")){
54+
plugin.getDataHandler().getConfig().set(key, null);
55+
Bukkit.getConsoleSender().sendMessage("§aSuccessfully deleted the §ewin and/or lose §acounter of the map §e"+key.split("\\.")[1]);
56+
plugin.getDataHandler().save();
57+
}
58+
}
4159
}
4260

4361
public ConfigHandler getConfigHandler() {
@@ -56,6 +74,10 @@ public CubicCountdown getPlugin() {
5674
return plugin;
5775
}
5876

77+
public Metrics getMetrics() {
78+
return metrics;
79+
}
80+
5981
public DataHandler getDataHandler() {
6082
return dataHandler;
6183
}
@@ -69,10 +91,28 @@ public List<Cube> getCubes() {
6991
}
7092
}
7193
List<Cube> cubeList = new ArrayList<>();
72-
cubeStringList.forEach(string -> cubeList.add(new Cube(string, dataHandler.getLocation("Cube." + string + ".Pos1"), dataHandler.getLocation("Cube." + string + ".Pos2"))));
94+
cubeStringList.forEach(string -> cubeList.add(new Cube(string, dataHandler.getLocation("Cube." + string + ".Pos1"), dataHandler.getLocation("Cube." + string + ".Pos2"), this)));
7395
return cubeList;
7496
}
7597

98+
public boolean viewingCountdown(Player player){
99+
AtomicBoolean viewing = new AtomicBoolean(false);
100+
getCountdownList().forEach(countdownModule -> {
101+
if(countdownModule.getCubicSettings().playerList().contains(player)){
102+
viewing.set(true);
103+
}
104+
});
105+
return viewing.get();
106+
}
107+
108+
public void removeCountdown(CountdownModule countdownModule){
109+
countdownList.forEach(countdownModule1 -> {
110+
if(countdownModule1.getCountdownId() == countdownModule.getCountdownId()){
111+
countdownList.remove(countdownModule1);
112+
}
113+
});
114+
}
115+
76116
public CountdownModule getCountdownModuleFromCube(Cube cube) {
77117
AtomicReference<CountdownModule> finalCountdownModule = new AtomicReference<>();
78118
countdownList.forEach(countdownModule -> {
@@ -84,29 +124,47 @@ public CountdownModule getCountdownModuleFromCube(Cube cube) {
84124
}
85125

86126
public Integer getWins(Cube cube){
87-
return getDataHandler().getInteger("Cube."+cube.getName()+".Wins");
127+
return getDataHandler().getInteger("Cube."+cube.getName()+".WinCounter");
128+
}
129+
130+
public Integer getWins(String cube){
131+
return getDataHandler().getInteger("Cube."+cube+".WinCounter");
88132
}
89133

90134
public void increaseWins(Cube cube){
91135
Integer integer = 1;
92-
if(getDataHandler().keyExists("Cube."+cube.getName()+".Wins")){
93-
integer = (getDataHandler().getInteger("Cube."+cube.getName()+".Wins")+1);
136+
if(getDataHandler().keyExists("Cube."+cube.getName()+".WinCounter")){
137+
integer = (getDataHandler().getInteger("Cube."+cube.getName()+".WinCounter")+1);
94138
}
95-
getDataHandler().getConfig().set("Cube."+cube.getName()+".Wins", integer);
139+
getDataHandler().getConfig().set("Cube."+cube.getName()+".WinCounter", integer);
96140
getDataHandler().save();
97141
}
98142

99143
public Integer getLoses(Cube cube){
100-
return getDataHandler().getInteger("Cube."+cube.getName()+".Loses");
144+
return getDataHandler().getInteger("Cube."+cube.getName()+".LoseCounter");
145+
}
146+
147+
public Integer getLoses(String cube){
148+
return getDataHandler().getInteger("Cube."+cube+".LoseCounter");
101149
}
102150

103151
public void increaseLoses(Cube cube){
104152
Integer integer = 1;
105-
if(getDataHandler().keyExists("Cube."+cube.getName()+".Loses")){
106-
integer = (getDataHandler().getInteger("Cube."+cube.getName()+".Loses")+1);
153+
if(getDataHandler().keyExists("Cube."+cube.getName()+".LoseCounter")){
154+
integer = (getDataHandler().getInteger("Cube."+cube.getName()+".LoseCounter")+1);
107155
}
108-
getDataHandler().getConfig().set("Cube."+cube.getName()+".Loses", integer);
156+
getDataHandler().getConfig().set("Cube."+cube.getName()+".LoseCounter", integer);
109157
getDataHandler().save();
110158
}
111159

160+
public boolean cubeNameExists(String name){
161+
AtomicBoolean exists = new AtomicBoolean(false);
162+
getCubes().forEach(cube -> {
163+
if(cube.getName().equalsIgnoreCase(name)){
164+
exists.set(true);
165+
}
166+
});
167+
return exists.get();
168+
}
169+
112170
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package de.timecoding.cc.api;
2+
3+
import de.timecoding.cc.CubicCountdown;
4+
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
5+
import org.bukkit.OfflinePlayer;
6+
import org.bukkit.entity.Player;
7+
8+
public class CubicExpansion extends PlaceholderExpansion {
9+
10+
private CubicCountdown plugin;
11+
12+
public CubicExpansion(CubicCountdown plugin){
13+
this.plugin = plugin;
14+
}
15+
16+
@Override
17+
public String getIdentifier() {
18+
return "CC_PAPI";
19+
}
20+
21+
@Override
22+
public String getAuthor() {
23+
return "TimeCode";
24+
}
25+
26+
@Override
27+
public String getVersion() {
28+
return "1.0";
29+
}
30+
31+
@Override
32+
public boolean persist(){
33+
return true;
34+
}
35+
36+
@Override
37+
public String onRequest(OfflinePlayer player, String params) {
38+
if(params.startsWith("%win_counter_") && params.endsWith("%")){
39+
String cubeName = params.substring(13, (params.length()-1));
40+
if(plugin.cubeNameExists(cubeName)){
41+
return plugin.getWins(cubeName).toString();
42+
}else{
43+
return null;
44+
}
45+
}else if(params.startsWith("%lose_counter_") && params.endsWith("%")){
46+
String cubeName = params.substring(14, (params.length()-1));
47+
if(plugin.cubeNameExists(cubeName)){
48+
return plugin.getLoses(cubeName).toString();
49+
}else{
50+
return null;
51+
}
52+
}
53+
return null;
54+
}
55+
}

0 commit comments

Comments
 (0)