-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from LaBoulangerie/1.21
1.21
- Loading branch information
Showing
29 changed files
with
244 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 14 additions & 24 deletions
38
src/main/java/net/laboulangerie/laboulangeriemmo/betonquest/LevelCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,26 @@ | ||
package net.laboulangerie.laboulangeriemmo.betonquest; | ||
|
||
import java.util.UUID; | ||
|
||
import org.bukkit.Bukkit; | ||
|
||
import org.betonquest.betonquest.api.profiles.Profile; | ||
import org.betonquest.betonquest.api.quest.condition.PlayerCondition; | ||
import org.betonquest.betonquest.exceptions.QuestRuntimeException; | ||
import net.laboulangerie.laboulangeriemmo.LaBoulangerieMmo; | ||
import net.laboulangerie.laboulangeriemmo.api.player.MmoPlayer; | ||
import pl.betoncraft.betonquest.Instruction; | ||
import pl.betoncraft.betonquest.api.Condition; | ||
import pl.betoncraft.betonquest.exceptions.InstructionParseException; | ||
import pl.betoncraft.betonquest.exceptions.QuestRuntimeException; | ||
|
||
public class LevelCondition extends Condition { | ||
|
||
@SuppressWarnings("deprecation") | ||
public LevelCondition(Instruction instruction) { | ||
super(instruction); | ||
public class LevelCondition implements PlayerCondition { | ||
private String talentName; | ||
private int level; | ||
public LevelCondition(String talentName, int level) { | ||
this.talentName = talentName; | ||
this.level = level; | ||
} | ||
|
||
@Override | ||
protected Boolean execute(String playerID) throws QuestRuntimeException { | ||
public boolean check(Profile profile) throws QuestRuntimeException { | ||
MmoPlayer mmoPlayer = LaBoulangerieMmo.PLUGIN.getMmoPlayerManager() | ||
.getPlayer(Bukkit.getPlayer(UUID.fromString(playerID))); | ||
.getPlayer(profile.getPlayer().getPlayer()); | ||
if (mmoPlayer == null) return false; // Shouldn't happen but just in case | ||
|
||
String talentName = ""; | ||
try { | ||
talentName = instruction.getPart(1); | ||
} catch (InstructionParseException e) { | ||
e.printStackTrace(); | ||
} | ||
return instruction.getAllNumbers().get(0) <= mmoPlayer.getTalent(talentName).getLevel(); | ||
|
||
return level <= mmoPlayer.getTalent(talentName).getLevel(); | ||
} | ||
|
||
} |
53 changes: 18 additions & 35 deletions
53
src/main/java/net/laboulangerie/laboulangeriemmo/betonquest/XpEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,39 @@ | ||
package net.laboulangerie.laboulangeriemmo.betonquest; | ||
|
||
import java.util.UUID; | ||
|
||
import org.bukkit.Bukkit; | ||
|
||
import org.betonquest.betonquest.api.profiles.Profile; | ||
import org.betonquest.betonquest.api.quest.event.Event; | ||
import org.betonquest.betonquest.exceptions.QuestRuntimeException; | ||
import net.laboulangerie.laboulangeriemmo.LaBoulangerieMmo; | ||
import net.laboulangerie.laboulangeriemmo.api.player.MmoPlayer; | ||
import pl.betoncraft.betonquest.Instruction; | ||
import pl.betoncraft.betonquest.api.QuestEvent; | ||
import pl.betoncraft.betonquest.exceptions.InstructionParseException; | ||
import pl.betoncraft.betonquest.exceptions.QuestRuntimeException; | ||
|
||
public class XpEvent extends QuestEvent { | ||
public class XpEvent implements Event { | ||
String talentName; | ||
char op; | ||
double xp; | ||
|
||
@SuppressWarnings("deprecation") | ||
public XpEvent(Instruction instruction) throws InstructionParseException { | ||
super(instruction); | ||
public XpEvent(String talentName, char op, double xp) { | ||
this.talentName = talentName; | ||
this.op = op; | ||
this.xp = xp; | ||
} | ||
|
||
@Override | ||
protected Void execute(String playerID) throws QuestRuntimeException { | ||
public void execute(Profile profile) throws QuestRuntimeException { | ||
MmoPlayer mmoPlayer = LaBoulangerieMmo.PLUGIN.getMmoPlayerManager() | ||
.getPlayer(Bukkit.getPlayer(UUID.fromString(playerID))); | ||
if (mmoPlayer == null) return null; // Shouldn't happen but just in case | ||
.getPlayer(profile.getPlayer().getPlayer()); | ||
if (mmoPlayer == null) return; // Shouldn't happen but just in case | ||
|
||
String talentName = ""; | ||
String rawValue = ""; | ||
try { | ||
talentName = instruction.getPart(1); | ||
rawValue = instruction.getPart(2); | ||
} catch (InstructionParseException e) { | ||
e.printStackTrace(); | ||
} | ||
double value = 0; | ||
try { | ||
value = Double.parseDouble(rawValue.substring(1)); | ||
} catch (NumberFormatException error) { | ||
throw new QuestRuntimeException("Unable to parse given value to a decimal number", | ||
error); | ||
} | ||
switch (rawValue.charAt(0)) { | ||
switch (op) { | ||
case '+': | ||
mmoPlayer.getTalent(talentName).incrementXp(value); | ||
mmoPlayer.getTalent(talentName).incrementXp(xp); | ||
break; | ||
case '-': | ||
mmoPlayer.getTalent(talentName).decrementXp(value); | ||
mmoPlayer.getTalent(talentName).decrementXp(xp); | ||
break; | ||
default: | ||
throw new QuestRuntimeException("Unknown operation: " + rawValue.charAt(0) | ||
throw new QuestRuntimeException("Unknown operation: " + op | ||
+ ", should be either '+' or '-'"); | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.