Skip to content

Commit

Permalink
Bug fix: Fixed the bug AdvancementListener.java can only get adventur…
Browse files Browse the repository at this point in the history
…e achievements (And a bug causes server backend to report error)
  • Loading branch information
eofitg committed Jun 25, 2023
1 parent cf8874c commit a039605
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@
public class AdvancementListener extends PointListener {

private static final String configName = "advancement";
private static final String[] advancements = {"minecraft:adventure/", "minecraft:end/", "minecraft:nether/", "minecraft:husbandry/", "minecraft:story/"};

@EventHandler
public void onFinishAdvancement(PlayerAdvancementDoneEvent e) {
public void finishAdvancement(PlayerAdvancementDoneEvent e) {

// If plugin is disabled
if (!state) return;

String key = e.getAdvancement().getKey().toString();
// Only adventure advancement
if (!key.startsWith("minecraft:adventure")) return;
if (isAdvancement(key) == null) return;

UUID uuid = e.getPlayer().getUniqueId();
String name = e.getPlayer().getName();
Player player = e.getPlayer();
String title = e.getAdvancement().getDisplay().getTitle();
String advancement = key.substring(isAdvancement(key).length());

// Get advancement settings config
AdvancementConfig advancementConfig = new AdvancementConfig();
Expand All @@ -40,7 +41,7 @@ public void onFinishAdvancement(PlayerAdvancementDoneEvent e) {
// This event's triggered state
boolean triggered = userDataConfig.triggered(configName);
// The object of this event's triggered state
boolean objectTriggered = userDataConfig.triggered(configName, title);
boolean objectTriggered = userDataConfig.triggered(configName, advancement);

if (!triggered) {
userDataConfig.setLimit(configName, 1);
Expand All @@ -52,9 +53,18 @@ public void onFinishAdvancement(PlayerAdvancementDoneEvent e) {

double userPoint = userDataConfig.getPoint() + parsePoint(advancementConfig.getPoint());
userDataConfig.setPoint(userPoint);
userDataConfig.setTriggered(configName, title, true);
userDataConfig.setTriggered(configName, advancement, true);
userDataConfig.save();

}

private static String isAdvancement(String str) {
for (String s : advancements) {
if (str.startsWith(s)) {
return s;
}
}
return null;
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package com.eofitg.hardcore.listener.pointlistener;

import com.eofitg.hardcore.listener.PointListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.player.PlayerMoveEvent;

public class StructureListener extends PointListener {

private static final String configName = "structure";

@EventHandler
public void arriveStructure(PlayerMoveEvent e) {
}

}

0 comments on commit a039605

Please sign in to comment.