mirror of
https://github.com/songoda/FabledSkyBlock.git
synced 2025-02-10 08:41:22 +01:00
Added ECO and BANK to challenges
This commit is contained in:
parent
898dd64d7a
commit
6730c53fa1
@ -1,12 +1,9 @@
|
|||||||
package com.songoda.skyblock.challenge.challenge;
|
package com.songoda.skyblock.challenge.challenge;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import com.songoda.core.compatibility.CompatibleMaterial;
|
import com.songoda.core.compatibility.CompatibleMaterial;
|
||||||
|
import com.songoda.core.hooks.EconomyManager;
|
||||||
import com.songoda.skyblock.SkyBlock;
|
import com.songoda.skyblock.SkyBlock;
|
||||||
|
import com.songoda.skyblock.bank.BankManager;
|
||||||
import com.songoda.skyblock.island.Island;
|
import com.songoda.skyblock.island.Island;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -19,17 +16,20 @@ import org.bukkit.inventory.meta.PotionMeta;
|
|||||||
import org.bukkit.potion.PotionData;
|
import org.bukkit.potion.PotionData;
|
||||||
import org.bukkit.potion.PotionType;
|
import org.bukkit.potion.PotionType;
|
||||||
|
|
||||||
import com.songoda.skyblock.api.SkyBlockAPI;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class Challenge {
|
public class Challenge {
|
||||||
private ChallengeCategory category;
|
private final ChallengeCategory category;
|
||||||
private int id;
|
private final int id;
|
||||||
private String name;
|
private final String name;
|
||||||
private int maxTimes;
|
private final int maxTimes;
|
||||||
private boolean showInChat;
|
private final boolean showInChat;
|
||||||
private List<Peer<Type, Object>> requires;
|
private List<Peer<Type, Object>> requires;
|
||||||
private List<Peer<Type, Object>> rewards;
|
private List<Peer<Type, Object>> rewards;
|
||||||
private ItemChallenge item;
|
private final ItemChallenge item;
|
||||||
|
|
||||||
public Challenge(ChallengeCategory category, int id, String name, int maxTimes, boolean showInChat,
|
public Challenge(ChallengeCategory category, int id, String name, int maxTimes, boolean showInChat,
|
||||||
List<String> requires, List<String> rewards, ItemChallenge item) {
|
List<String> requires, List<String> rewards, ItemChallenge item) {
|
||||||
@ -55,7 +55,7 @@ public class Challenge {
|
|||||||
String arg1 = str.substring(idx + 1);
|
String arg1 = str.substring(idx + 1);
|
||||||
try {
|
try {
|
||||||
Type t = Type.valueOf(arg0);
|
Type t = Type.valueOf(arg0);
|
||||||
this.requires.add(new Peer<Type, Object>(t, t.convert(arg1)));
|
this.requires.add(new Peer<>(t, t.convert(arg1)));
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
throw new IllegalArgumentException("Invalid line : " + str + " : " + ex.getMessage());
|
throw new IllegalArgumentException("Invalid line : " + str + " : " + ex.getMessage());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -71,7 +71,7 @@ public class Challenge {
|
|||||||
String arg1 = str.substring(idx + 1);
|
String arg1 = str.substring(idx + 1);
|
||||||
try {
|
try {
|
||||||
Type t = Type.valueOf(arg0);
|
Type t = Type.valueOf(arg0);
|
||||||
this.rewards.add(new Peer<Type, Object>(t, t.convert(arg1)));
|
this.rewards.add(new Peer<>(t, t.convert(arg1)));
|
||||||
} catch (IllegalArgumentException ex) {
|
} catch (IllegalArgumentException ex) {
|
||||||
throw new IllegalArgumentException("Invalid line : " + str + ": " + ex.getMessage());
|
throw new IllegalArgumentException("Invalid line : " + str + ": " + ex.getMessage());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@ -114,7 +114,7 @@ public class Challenge {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum Type {
|
public enum Type {
|
||||||
ITEM {
|
ITEM {
|
||||||
// An item
|
// An item
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ public class Challenge {
|
|||||||
* Convert the value to a useable ItemStack
|
* Convert the value to a useable ItemStack
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Object convert(String value) throws IllegalArgumentException {
|
public ItemStack convert(String value) throws IllegalArgumentException {
|
||||||
if (value == null || "".equalsIgnoreCase(value.trim()))
|
if (value == null || "".equalsIgnoreCase(value.trim()))
|
||||||
throw new IllegalArgumentException("Value is empty or null");
|
throw new IllegalArgumentException("Value is empty or null");
|
||||||
int index = value.indexOf(' ');
|
int index = value.indexOf(' ');
|
||||||
@ -195,7 +195,7 @@ public class Challenge {
|
|||||||
// A command to execute
|
// A command to execute
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object convert(String value) throws IllegalArgumentException {
|
public String convert(String value) throws IllegalArgumentException {
|
||||||
// Here we don't have to convert the value because the value is the command
|
// Here we don't have to convert the value because the value is the command
|
||||||
if (value == null || "".equalsIgnoreCase(value))
|
if (value == null || "".equalsIgnoreCase(value))
|
||||||
throw new IllegalArgumentException("Value is empty or null");
|
throw new IllegalArgumentException("Value is empty or null");
|
||||||
@ -224,7 +224,7 @@ public class Challenge {
|
|||||||
// The level of island of a player
|
// The level of island of a player
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object convert(String value) throws IllegalArgumentException {
|
public Integer convert(String value) throws IllegalArgumentException {
|
||||||
// Convert the value to an Integer representing the minimum level of island
|
// Convert the value to an Integer representing the minimum level of island
|
||||||
// required
|
// required
|
||||||
if (value == null || "".equalsIgnoreCase(value))
|
if (value == null || "".equalsIgnoreCase(value))
|
||||||
@ -262,7 +262,7 @@ public class Challenge {
|
|||||||
NEAR {
|
NEAR {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object convert(String value) throws IllegalArgumentException {
|
public Peer<EntityType, Integer> convert(String value) throws IllegalArgumentException {
|
||||||
// We returns the entity type and the number of entity required
|
// We returns the entity type and the number of entity required
|
||||||
if (value == null || "".equalsIgnoreCase(value))
|
if (value == null || "".equalsIgnoreCase(value))
|
||||||
throw new IllegalArgumentException("Value is empty or null");
|
throw new IllegalArgumentException("Value is empty or null");
|
||||||
@ -320,7 +320,7 @@ public class Challenge {
|
|||||||
private Pattern space = Pattern.compile(" ");
|
private Pattern space = Pattern.compile(" ");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object convert(String value) throws IllegalArgumentException {
|
public Peer<PotionType, Peer<Integer, Integer>> convert(String value) throws IllegalArgumentException {
|
||||||
// We returns the potion required
|
// We returns the potion required
|
||||||
if (value == null || "".equalsIgnoreCase(value))
|
if (value == null || "".equalsIgnoreCase(value))
|
||||||
throw new IllegalArgumentException("Value is empty or null");
|
throw new IllegalArgumentException("Value is empty or null");
|
||||||
@ -336,9 +336,6 @@ public class Challenge {
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"\"" + split[0] + "\" isn't a correct Minecraft PotionType (value = \"" + value + "\")");
|
"\"" + split[0] + "\" isn't a correct Minecraft PotionType (value = \"" + value + "\")");
|
||||||
}
|
}
|
||||||
if (pt == null)
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"\"" + split[0] + "\" isn't a correct Minecraft PotionType (value = \"" + value + "\")");
|
|
||||||
// The data
|
// The data
|
||||||
int data;
|
int data;
|
||||||
try {
|
try {
|
||||||
@ -356,7 +353,7 @@ public class Challenge {
|
|||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"\"" + split[2] + "\" isn't a correct number (value = \"" + value + "\")");
|
"\"" + split[2] + "\" isn't a correct number (value = \"" + value + "\")");
|
||||||
}
|
}
|
||||||
return new Peer<PotionType, Peer<Integer, Integer>>(pt, new Peer<>(data, amount));
|
return new Peer<>(pt, new Peer<>(data, amount));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -441,11 +438,6 @@ public class Challenge {
|
|||||||
* <li>7 = lingering extended</li>
|
* <li>7 = lingering extended</li>
|
||||||
* <li>8 = lingering ++</li>
|
* <li>8 = lingering ++</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
|
||||||
* @param is
|
|
||||||
* @param type
|
|
||||||
* @param data
|
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
private boolean isSame(ItemStack is, PotionType type, int data) {
|
private boolean isSame(ItemStack is, PotionType type, int data) {
|
||||||
if (data <= 2 && is.getType() != Material.POTION)
|
if (data <= 2 && is.getType() != Material.POTION)
|
||||||
@ -462,9 +454,85 @@ public class Challenge {
|
|||||||
return false;
|
return false;
|
||||||
else if ((data == 1 || data == 4 || data == 7) && !pd.isExtended())
|
else if ((data == 1 || data == 4 || data == 7) && !pd.isExtended())
|
||||||
return false;
|
return false;
|
||||||
else if ((data == 2 || data == 5 || data == 8) && !pd.isUpgraded())
|
else return (data != 2 && data != 5 && data != 8) || pd.isUpgraded();
|
||||||
return false;
|
}
|
||||||
return true;
|
},
|
||||||
|
ECO {
|
||||||
|
@Override
|
||||||
|
public Double convert(String value) throws IllegalArgumentException {
|
||||||
|
if (value == null || "".equalsIgnoreCase(value))
|
||||||
|
throw new IllegalArgumentException("Value is empty or null");
|
||||||
|
try {
|
||||||
|
return Double.parseDouble(value);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"\"" + value + "\" isn't a correct number (value = \"" + value + "\")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean has(Player p, Object obj) {
|
||||||
|
if (obj instanceof Number) {
|
||||||
|
return EconomyManager.getBalance(p) >= ((Number) obj).doubleValue();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeRequire(Player p, Object obj) {
|
||||||
|
if (obj instanceof Number && ((Number) obj).doubleValue() > 0) {
|
||||||
|
EconomyManager.withdrawBalance(p, ((Number) obj).doubleValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeReward(Player p, Object obj) {
|
||||||
|
if (obj instanceof Number && ((Number) obj).doubleValue() > 0) {
|
||||||
|
EconomyManager.deposit(p, ((Number) obj).doubleValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
BANK {
|
||||||
|
@Override
|
||||||
|
public Double convert(String value) throws IllegalArgumentException {
|
||||||
|
if (value == null || "".equalsIgnoreCase(value))
|
||||||
|
throw new IllegalArgumentException("Value is empty or null");
|
||||||
|
try {
|
||||||
|
return Double.parseDouble(value);
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"\"" + value + "\" isn't a correct number (value = \"" + value + "\")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean has(Player p, Object obj) {
|
||||||
|
Island is = SkyBlock.getInstance().getIslandManager().getIsland(p);
|
||||||
|
|
||||||
|
if (is != null && obj instanceof Number && ((Number) obj).doubleValue() > 0) {
|
||||||
|
return is.getBankBalance() >= ((Number) obj).doubleValue();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeRequire(Player p, Object obj) {
|
||||||
|
Island is = SkyBlock.getInstance().getIslandManager().getIsland(p);
|
||||||
|
BankManager bankManager = SkyBlock.getInstance().getBankManager();
|
||||||
|
|
||||||
|
if (is != null && obj instanceof Number && ((Number) obj).doubleValue() > 0) {
|
||||||
|
bankManager.withdraw(p, is, ((Number) obj).doubleValue(), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void executeReward(Player p, Object obj) {
|
||||||
|
Island is = SkyBlock.getInstance().getIslandManager().getIsland(p);
|
||||||
|
BankManager bankManager = SkyBlock.getInstance().getBankManager();
|
||||||
|
|
||||||
|
if (is != null && obj instanceof Number) {
|
||||||
|
bankManager.deposit(p, is, ((Number) obj).doubleValue(), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -173,10 +173,12 @@ public class PlayerManager {
|
|||||||
done.put(c, count + 1);
|
done.put(c, count + 1);
|
||||||
addChallenge(uuid, c);
|
addChallenge(uuid, c);
|
||||||
// Take items
|
// Take items
|
||||||
for (Peer<Type, Object> peer : c.getRequires())
|
for (Peer<Type, Object> peer : c.getRequires()) {
|
||||||
peer.getKey().executeRequire(p, peer.getValue());
|
peer.getKey().executeRequire(p, peer.getValue());
|
||||||
for (Peer<Type, Object> peer : c.getRewards())
|
}
|
||||||
|
for (Peer<Type, Object> peer : c.getRewards()) {
|
||||||
peer.getKey().executeReward(p, peer.getValue());
|
peer.getKey().executeReward(p, peer.getValue());
|
||||||
|
}
|
||||||
// Ok, send message
|
// Ok, send message
|
||||||
String broadcast = ChatColor.translateAlternateColorCodes('&',
|
String broadcast = ChatColor.translateAlternateColorCodes('&',
|
||||||
SkyBlock.getInstance().getFileManager()
|
SkyBlock.getInstance().getFileManager()
|
||||||
|
@ -324,12 +324,15 @@ challenges:
|
|||||||
# LEVEL:<level> ==> the player's island needs to be at least <level> level
|
# LEVEL:<level> ==> the player's island needs to be at least <level> level
|
||||||
# NEAR:<EntityType> <amount> ==> <amount> of <EntityType> must be next to the player
|
# NEAR:<EntityType> <amount> ==> <amount> of <EntityType> must be next to the player
|
||||||
# POTION:<PotionType> <data> <amount>
|
# POTION:<PotionType> <data> <amount>
|
||||||
|
# BANK:<amount>
|
||||||
|
# ECO:<amount>
|
||||||
# data must be: 0 = normal potion, 1 = extended, 2 = ++, 3 = splash, 4 = splash extended, 5 = splash ++, 6 = lingering, 7 = lingering extended, 8 = lingering ++
|
# data must be: 0 = normal potion, 1 = extended, 2 = ++, 3 = splash, 4 = splash extended, 5 = splash ++, 6 = lingering, 7 = lingering extended, 8 = lingering ++
|
||||||
require:
|
require:
|
||||||
- 'ITEM:cobblestone 128'
|
- 'ITEM:cobblestone 128'
|
||||||
# The reward
|
# The reward
|
||||||
# ITEM:<item> <count> means the player will have <count> <item> when the challenge is done
|
# ITEM:<item> <count> means the player will have <count> <item> when the challenge is done
|
||||||
# CMD:<cmd> means a command will be executed by the console when the challenge is done
|
# CMD:<cmd> means a command will be executed by the console when the challenge is done
|
||||||
|
# BANK:<amount>
|
||||||
reward:
|
reward:
|
||||||
- 'CMD:eco give {player} 100'
|
- 'CMD:eco give {player} 100'
|
||||||
- 'ITEM:iron_ingot 20'
|
- 'ITEM:iron_ingot 20'
|
||||||
@ -565,7 +568,8 @@ challenges:
|
|||||||
- 'ITEM:cake 5'
|
- 'ITEM:cake 5'
|
||||||
- 'ITEM:pumpkin_pie 16'
|
- 'ITEM:pumpkin_pie 16'
|
||||||
reward:
|
reward:
|
||||||
- 'CMD:eco give {player} 300'
|
- 'CMD:eco give {player} 150'
|
||||||
|
- 'BANK:150'
|
||||||
- 'ITEM:diamond 10'
|
- 'ITEM:diamond 10'
|
||||||
- 'ITEM:cow_spawn_egg 1'
|
- 'ITEM:cow_spawn_egg 1'
|
||||||
maxtimes: 1
|
maxtimes: 1
|
||||||
@ -583,7 +587,8 @@ challenges:
|
|||||||
- '&c&lRewards:'
|
- '&c&lRewards:'
|
||||||
- '&e- 10 diamonds'
|
- '&e- 10 diamonds'
|
||||||
- '&e- 1 cow spawn egg'
|
- '&e- 1 cow spawn egg'
|
||||||
- '&e- 300 $'
|
- '&e- 150 $'
|
||||||
|
- '&e- 150 $ to the bank island'
|
||||||
'2':
|
'2':
|
||||||
id: 2
|
id: 2
|
||||||
name: '&2Hunter'
|
name: '&2Hunter'
|
||||||
@ -1077,6 +1082,7 @@ challenges:
|
|||||||
name: '&2The Neighbours'
|
name: '&2The Neighbours'
|
||||||
require:
|
require:
|
||||||
- 'NEAR:villager 10'
|
- 'NEAR:villager 10'
|
||||||
|
- 'BANK:100'
|
||||||
reward:
|
reward:
|
||||||
- 'CMD:eco give {player} 1000'
|
- 'CMD:eco give {player} 1000'
|
||||||
- 'ITEM:diamond_block 16'
|
- 'ITEM:diamond_block 16'
|
||||||
@ -1091,6 +1097,7 @@ challenges:
|
|||||||
lore:
|
lore:
|
||||||
- '&c&lFor this challenge, you''ll need:'
|
- '&c&lFor this challenge, you''ll need:'
|
||||||
- '&e- Have 10 villagers in your proximity'
|
- '&e- Have 10 villagers in your proximity'
|
||||||
|
- '&e- 100 $ in the island bank'
|
||||||
- '&c&lRewards:'
|
- '&c&lRewards:'
|
||||||
- '&e- 16 diamond blocks'
|
- '&e- 16 diamond blocks'
|
||||||
- '&e- 1000 $'
|
- '&e- 1000 $'
|
||||||
@ -1820,6 +1827,7 @@ challenges:
|
|||||||
id: 8
|
id: 8
|
||||||
name: '&4THE IMPOSSIBLE CHALLENGE'
|
name: '&4THE IMPOSSIBLE CHALLENGE'
|
||||||
require:
|
require:
|
||||||
|
- 'ECO:10000'
|
||||||
- 'ITEM:bedrock 64'
|
- 'ITEM:bedrock 64'
|
||||||
reward:
|
reward:
|
||||||
- 'CMD:eco give {player} 0'
|
- 'CMD:eco give {player} 0'
|
||||||
|
Loading…
Reference in New Issue
Block a user