Skip to content

Commit 7024ad9

Browse files
committed
Add completed score logic
1 parent c122fdd commit 7024ad9

11 files changed

+590
-207
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>me.loutreee</groupId>
88
<artifactId>statcraft</artifactId>
9-
<version>2.1.0</version>
9+
<version>2.2.0</version>
1010
<packaging>jar</packaging>
1111

1212
<name>statcraft</name>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package me.loutreee.statCraft;
2+
3+
import org.bukkit.configuration.ConfigurationSection;
4+
import org.bukkit.configuration.file.FileConfiguration;
5+
import org.bukkit.plugin.java.JavaPlugin;
6+
import org.bukkit.Material;
7+
import org.bukkit.entity.EntityType;
8+
9+
import java.util.HashMap;
10+
import java.util.List;
11+
import java.util.Map;
12+
13+
public class ConfigLoader {
14+
15+
private final JavaPlugin plugin;
16+
private final Map<Material, Integer> blockScores = new HashMap<>();
17+
private final Map<Material, Integer> craftScores = new HashMap<>();
18+
private final Map<EntityType, Integer> mobScores = new HashMap<>();
19+
private int webPort = 27800; // valeur par défaut
20+
21+
public ConfigLoader(JavaPlugin plugin) {
22+
this.plugin = plugin;
23+
plugin.saveDefaultConfig(); // crée le config.yml si inexistant
24+
loadConfig();
25+
}
26+
27+
private void loadConfig() {
28+
FileConfiguration config = plugin.getConfig();
29+
30+
// Récupère le port
31+
webPort = config.getInt("Web.port", 27800);
32+
33+
// Lecture des blocks
34+
ConfigurationSection survivalSection = config.getConfigurationSection("Survival");
35+
if (survivalSection != null) {
36+
// Blocks
37+
List<Map<?, ?>> blocksList = survivalSection.getMapList("blocks");
38+
for (Map<?, ?> entry : blocksList) {
39+
String name = (String) entry.get("name");
40+
int score = (int) entry.get("score");
41+
Material mat = Material.matchMaterial(name);
42+
if (mat != null) {
43+
blockScores.put(mat, score);
44+
}
45+
}
46+
47+
// Mobs
48+
List<Map<?, ?>> mobsList = survivalSection.getMapList("mobs");
49+
for (Map<?, ?> entry : mobsList) {
50+
String name = (String) entry.get("name");
51+
int score = (int) entry.get("score");
52+
try {
53+
EntityType et = EntityType.valueOf(name);
54+
mobScores.put(et, score);
55+
} catch (IllegalArgumentException e) {
56+
plugin.getLogger().warning("Mob inconnu dans config: " + name);
57+
}
58+
}
59+
60+
// Crafts
61+
List<Map<?, ?>> craftsList = survivalSection.getMapList("crafts");
62+
for (Map<?, ?> entry : craftsList) {
63+
String name = (String) entry.get("name");
64+
int score = (int) entry.get("score");
65+
Material mat = Material.matchMaterial(name);
66+
if (mat != null) {
67+
craftScores.put(mat, score);
68+
}
69+
}
70+
}
71+
}
72+
73+
public int getWebPort() {
74+
return webPort;
75+
}
76+
77+
public int getBlockScore(Material mat) {
78+
return blockScores.getOrDefault(mat, 0);
79+
}
80+
81+
public int getMobScore(EntityType et) {
82+
return mobScores.getOrDefault(et, 0);
83+
}
84+
85+
public int getCraftScore(Material mat) {
86+
return craftScores.getOrDefault(mat, 0);
87+
}
88+
}

src/main/java/me/loutreee/statCraft/PlayerStats.java

+77-8
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,30 @@
22

33
import org.bukkit.Material;
44
import org.bukkit.entity.EntityType;
5+
56
import java.util.HashMap;
67
import java.util.Map;
78

8-
/**
9-
* Contient les stats d'un joueur (blocs minés, items craftés, mobs tués).
10-
*/
119
public class PlayerStats {
1210

1311
private final String playerName;
12+
1413
private final Map<String, Integer> blocksMined = new HashMap<>();
1514
private final Map<String, Integer> itemsCrafted = new HashMap<>();
1615
private final Map<String, Integer> mobsKilled = new HashMap<>();
1716

17+
// Sous-scores
18+
private int blockScore = 0;
19+
private int craftScore = 0;
20+
private int mobScore = 0;
21+
private int timeScore = 0;
22+
23+
// Score total
24+
private int totalScore = 0;
25+
26+
// Pour gérer le temps de jeu (on stocke la dernière valeur connue)
27+
private int lastPlayTime = 0;
28+
1829
public PlayerStats(String playerName) {
1930
this.playerName = playerName;
2031
}
@@ -35,7 +46,23 @@ public Map<String, Integer> getMobsKilled() {
3546
return mobsKilled;
3647
}
3748

38-
// Incrémente les compteurs lors des événements
49+
// Sous-scores : getters
50+
public int getBlockScore() { return blockScore; }
51+
public int getCraftScore() { return craftScore; }
52+
public int getMobScore() { return mobScore; }
53+
public int getTimeScore() { return timeScore; }
54+
55+
public int getTotalScore() { return totalScore; }
56+
57+
public int getLastPlayTime() {
58+
return lastPlayTime;
59+
}
60+
61+
public void setLastPlayTime(int lastPlayTime) {
62+
this.lastPlayTime = lastPlayTime;
63+
}
64+
65+
// --- Incréments des compteurs en mémoire (pour blocs, items, mobs) ---
3966
public void incrementBlock(Material blockType) {
4067
blocksMined.merge(blockType.toString(), 1, Integer::sum);
4168
}
@@ -48,25 +75,67 @@ public void incrementMob(EntityType mobType) {
4875
mobsKilled.merge(mobType.toString(), 1, Integer::sum);
4976
}
5077

51-
// Méthodes pour initialiser les compteurs à partir d'une Map
78+
// --- Incréments des sous-scores (chaque action) ---
79+
public void addBlockScore(int amount) {
80+
blockScore += amount;
81+
totalScore += amount;
82+
}
83+
84+
public void addCraftScore(int amount) {
85+
craftScore += amount;
86+
totalScore += amount;
87+
}
88+
89+
public void addMobScore(int amount) {
90+
mobScore += amount;
91+
totalScore += amount;
92+
}
93+
94+
public void addTimeScore(int amount) {
95+
timeScore += amount;
96+
totalScore += amount;
97+
}
98+
99+
// --- Méthodes "set" pour restaurer à partir d'un snapshot ---
100+
52101
public void setBlocksMined(Map<String, Integer> blocks) {
53102
blocksMined.clear();
54-
if(blocks != null) {
103+
if (blocks != null) {
55104
blocksMined.putAll(blocks);
56105
}
57106
}
58107

59108
public void setItemsCrafted(Map<String, Integer> items) {
60109
itemsCrafted.clear();
61-
if(items != null) {
110+
if (items != null) {
62111
itemsCrafted.putAll(items);
63112
}
64113
}
65114

66115
public void setMobsKilled(Map<String, Integer> mobs) {
67116
mobsKilled.clear();
68-
if(mobs != null) {
117+
if (mobs != null) {
69118
mobsKilled.putAll(mobs);
70119
}
71120
}
121+
122+
public void setBlockScore(int blockScore) {
123+
this.blockScore = blockScore;
124+
}
125+
126+
public void setCraftScore(int craftScore) {
127+
this.craftScore = craftScore;
128+
}
129+
130+
public void setMobScore(int mobScore) {
131+
this.mobScore = mobScore;
132+
}
133+
134+
public void setTimeScore(int timeScore) {
135+
this.timeScore = timeScore;
136+
}
137+
138+
public void setTotalScore(int totalScore) {
139+
this.totalScore = totalScore;
140+
}
72141
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package me.loutreee.statCraft;
2+
3+
import org.bukkit.Material;
4+
import org.bukkit.entity.EntityType;
5+
6+
public class ScoreService {
7+
8+
private final ConfigLoader configLoader;
9+
10+
public ScoreService(ConfigLoader configLoader) {
11+
this.configLoader = configLoader;
12+
}
13+
14+
// Score pour un bloc miné
15+
public int getBlockScore(Material mat) {
16+
return configLoader.getBlockScore(mat);
17+
}
18+
19+
// Score pour un mob tué
20+
public int getMobScore(EntityType et) {
21+
return configLoader.getMobScore(et);
22+
}
23+
24+
// Score pour un item crafté
25+
public int getCraftScore(Material mat) {
26+
return configLoader.getCraftScore(mat);
27+
}
28+
29+
// Score pour 1 minute de jeu
30+
public int getTimeScore() {
31+
return 1; // 1 point par minute
32+
}
33+
}

0 commit comments

Comments
 (0)