Last commits cleanup
This commit is contained in:
Indyuce 2020-09-13 13:03:19 +02:00
commit 5cae155273
25 changed files with 339 additions and 231 deletions

View File

@ -21,7 +21,7 @@ cache:
build:
stage: build
script:
- mvn $MAVEN_CLI_OPTS package
- mvn $MAVEN_CLI_OPTS clean package
deploy:
stage: deploy

View File

@ -1 +1,4 @@
![eclipse_SEyunr6cEZ](/uploads/4537bd2ada7d70653c7e26a0efc88565/eclipse_SEyunr6cEZ.png)
Private repository for MMOCore.
Issues: https://git.lumine.io/mythiccraft/mmocore/-/issues
Wiki: https://git.lumine.io/mythiccraft/mmocore/-/wikis/home

Binary file not shown.

Binary file not shown.

324
pom.xml
View File

@ -1,166 +1,172 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore</artifactId>
<version>1.4.4</version>
<name>MMOCore</name>
<description>Offer your players a brand new RPG experience.</description>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.Indyuce</groupId>
<artifactId>MMOCore</artifactId>
<version>1.4.5</version>
<name>MMOCore</name>
<description>Offer your players a brand new RPG experience.</description>
<properties>
<build.number>SNAPSHOT</build.number>
<downloadSources>false</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<properties>
<build.number>SNAPSHOT</build.number>
<downloadSources>false</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<distributionManagement>
<repository>
<id>nexus</id>
<name>Lumine Releases</name>
<url>http://mvn.lumine.io/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Lumine Snapshots</name>
<url>http://mvn.lumine.io/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<distributionManagement>
<repository>
<id>nexus</id>
<name>Lumine Releases</name>
<url>http://mvn.lumine.io/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Lumine Snapshots</name>
<url>http://mvn.lumine.io/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<finalName>${project.name}-${project.version}</finalName>
<resources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<junitArtifactName>junit:junit</junitArtifactName>
<encoding>UTF-8</encoding>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<argLine>-ea -Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
</repositories>
<dependencies>
<build>
<finalName>${project.name}-${project.version}</finalName>
<resources>
<resource>
<filtering>true</filtering>
<directory>${basedir}/src/main/resources/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<junitArtifactName>junit:junit</junitArtifactName>
<encoding>UTF-8</encoding>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<argLine>-ea -Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>sk89q-repo</id>
<url>https://maven.enginehub.org/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>mmoitems</artifactId>
<version>5.1.2</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MMOItems.jar</systemPath>
</dependency>
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>MMOLib</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MMOLib.jar</systemPath>
</dependency>
<!-- MMOs -->
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>mmoitems</artifactId>
<version>6.1.2</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MMOItems.jar</systemPath>
</dependency>
<dependency>
<groupId>net.Indyuce</groupId>
<artifactId>MMOLib</artifactId>
<version>1.3</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MMOLib.jar</systemPath>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.14.4</version>
<scope>system</scope>
<systemPath>${basedir}/lib/spigot.jar</systemPath>
</dependency>
<dependency>
<groupId>com.bekvon.bukkit</groupId>
<artifactId>Residence</artifactId>
<version>4.8.7.2</version>
<scope>system</scope>
<systemPath>${basedir}/lib/Residence.jar</systemPath>
</dependency>
<dependency>
<groupId>com.Zrips</groupId>
<artifactId>CMI</artifactId>
<version>8.6.5.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/CMI.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sainttx.holograms</groupId>
<artifactId>holograms</artifactId>
<version>2.9.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/Holograms.jar</systemPath>
</dependency>
<dependency>
<groupId>com.gmail.filoghost</groupId>
<artifactId>HolographicDisplays</artifactId>
<version>6.9.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/HolographicDisplays.jar</systemPath>
</dependency>
<dependency>
<groupId>io.lumine.xikage</groupId>
<artifactId>MythicMobs</artifactId>
<version>4.8.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MythicMobs.jar</systemPath>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizens</artifactId>
<version>2.0.25-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/lib/Citizens.jar</systemPath>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.7</version>
<scope>system</scope>
<systemPath>${basedir}/lib/PlaceholderAPI.jar</systemPath>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>19.0.0</version>
</dependency>
</dependencies>
<!-- Minecraft -->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12-R1-1.16-R2</version>
<scope>system</scope>
<systemPath>${basedir}/lib/spigot.jar</systemPath>
</dependency>
<!-- APIs -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>19.0.0</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.41</version>
</dependency>
<!-- Other Plugins -->
<dependency>
<groupId>com.bekvon.bukkit</groupId>
<artifactId>Residence</artifactId>
<version>4.8.7.2</version>
<scope>system</scope>
<systemPath>${basedir}/lib/Residence.jar</systemPath>
</dependency>
<dependency>
<groupId>com.Zrips</groupId>
<artifactId>CMI</artifactId>
<version>8.6.5.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/CMI.jar</systemPath>
</dependency>
<dependency>
<groupId>com.sainttx.holograms</groupId>
<artifactId>holograms</artifactId>
<version>2.9.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/Holograms.jar</systemPath>
</dependency>
<dependency>
<groupId>com.gmail.filoghost</groupId>
<artifactId>HolographicDisplays</artifactId>
<version>6.9.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/HolographicDisplays.jar</systemPath>
</dependency>
<dependency>
<groupId>io.lumine.xikage</groupId>
<artifactId>MythicMobs</artifactId>
<version>4.8.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/MythicMobs.jar</systemPath>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.7</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-bukkit</artifactId>
<version>7.0.2-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.citizensnpcs</groupId>
<artifactId>citizens</artifactId>
<version>2.0.25-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/lib/Citizens.jar</systemPath>
</dependency>
<dependency>
<groupId>me.clip</groupId>
<artifactId>placeholderapi</artifactId>
<version>2.10.7</version>
<scope>system</scope>
<systemPath>${basedir}/lib/PlaceholderAPI.jar</systemPath>
</dependency>
</dependencies>
</project>

View File

@ -98,7 +98,7 @@ import net.mmogroup.mmolib.version.SpigotPlugin;
public class MMOCore extends JavaPlugin {
public static MMOCore plugin;
public ConfigManager configManager;
public WaypointManager waypointManager;
public RestrictionManager restrictionManager;

View File

@ -31,7 +31,7 @@ public class PlayerActionBar extends BukkitRunnable {
for (PlayerData data : PlayerData.getAll())
if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && data.canSeeActionBar()) {
data.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(MMOCore.plugin.placeholderParser.parse(data.getPlayer(),
MMOLib.plugin.parseColors(new String(format)
MMOLib.plugin.parseColors(new String(data.getProfess().hasActionBar() ? data.getProfess().getActionBar() : format)
.replace("{health}", digit.format(data.getPlayer().getHealth()))
.replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()))
.replace("{mana_icon}", data.getProfess().getManaDisplay().getIcon())

View File

@ -8,18 +8,16 @@ import net.Indyuce.mmocore.api.block.BlockInfo.RegeneratingBlock;
public interface BlockType {
public void place(Location loc, RegeneratingBlock regenerating);
// public boolean matches(Block block);
/*
* generates a key used to store the BlockInfo instance in the manager map, the
* key depends on the block type to make sure there is no interference
/**
* Generates a key used to store the BlockInfo instance in the manager map,
* the key depends on the block type to make sure there is no interference
*/
public String generateKey();
/*
* generateKey() determines if the block is handled by that block type,
* breakRestrictions(Block) applies some extra break restrictions; returns TRUE
* if the block can be broken
/**
* GenerateKey() determines if the block is handled by that block type,
* breakRestrictions(Block) applies some extra break restrictions; returns
* TRUE if the block can be broken
*/
public boolean breakRestrictions(Block block);
}

View File

@ -5,6 +5,8 @@ import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import net.Indyuce.mmocore.api.droptable.condition.Condition;
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
import org.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
@ -18,6 +20,7 @@ import net.mmogroup.mmolib.api.util.PostLoadObject;
public class DropTable extends PostLoadObject {
private final String id;
private final Set<DropItem> drops = new LinkedHashSet<>();
private final Set<Condition> conditions = new LinkedHashSet<>();
public DropTable(ConfigurationSection config) {
super(config);
@ -37,16 +40,24 @@ public class DropTable extends PostLoadObject {
*/
@Override
protected void whenPostLoaded(ConfigurationSection config) {
List<String> list = config.getStringList("items");
Validate.notNull(list, "Could not find drop item list");
List<String> itemsList = config.getStringList("items");
List<String> conditionsList = config.getStringList("conditions");
Validate.notNull(itemsList, "Could not find drop item list");
for (String key : list)
for (String key : itemsList)
try {
drops.add(MMOCore.plugin.loadManager.loadDropItem(new MMOLineConfig(key)));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load drop item '" + key + "' from table '" + id + "': " + exception.getMessage());
}
for (String key : conditionsList)
try {
conditions.add(MMOCore.plugin.loadManager.loadCondition(new MMOLineConfig(key)));
} catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load condition '" + key + "' from table '" + id + "': " + exception.getMessage());
}
}
public String getId() {
@ -69,4 +80,17 @@ public class DropTable extends PostLoadObject {
return builder.getLoot();
}
public Set<Condition> getConditions() {
return conditions;
}
public boolean areConditionsMet(ConditionInstance entity) {
for (Condition condition : this.getConditions()) {
if (!condition.isMet(entity)) {
return false;
}
}
return true;
}
}

View File

@ -14,7 +14,7 @@ public class BiomeCondition extends Condition {
super(config);
config.validate("name");
names = Arrays.asList(config.getString("name").split("\\,"));
names = Arrays.asList(config.getString("name").toUpperCase().split("\\,"));
}
@Override

View File

@ -0,0 +1,30 @@
package net.Indyuce.mmocore.api.droptable.condition;
import net.mmogroup.mmolib.api.MMOLineConfig;
import net.mmogroup.mmolib.api.player.MMOPlayerData;
import org.bukkit.entity.Player;
public class LevelCondition extends Condition {
private final int amount;
private final String profession;
public LevelCondition(MMOLineConfig config) {
super(config);
config.validate("amount");
amount = config.getInt("amount");
profession = config.contains("profession") ? config.getString("profession") : null;
}
@Override
public boolean isMet(ConditionInstance entity) {
if (entity.getEntity() instanceof Player) {
int level = (profession != null) ? MMOPlayerData.get((Player) entity.getEntity()).getMMOCore().getCollectionSkills().getLevel(profession)
: MMOPlayerData.get((Player) entity.getEntity()).getMMOCore().getLevel();
return level >= amount;
}
return false;
}
}

View File

@ -4,6 +4,7 @@ import org.apache.commons.lang.Validate;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.droptable.DropTable;
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
import net.Indyuce.mmocore.api.loot.LootBuilder;
import net.mmogroup.mmolib.api.MMOLineConfig;
@ -22,7 +23,8 @@ public class DropTableDropItem extends DropItem {
@Override
public void collect(LootBuilder builder) {
for (int j = 0; j < rollAmount(); j++)
builder.addLoot(dropTable.collect(builder));
if (dropTable.areConditionsMet(new ConditionInstance(builder.getEntity().getPlayer())))
for (int j = 0; j < rollAmount(); j++)
builder.addLoot(dropTable.collect(builder));
}
}

View File

@ -1,7 +1,9 @@
package net.Indyuce.mmocore.api.event;
import java.util.ArrayList;
import java.util.List;
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
import org.bukkit.block.Block;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@ -27,7 +29,8 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
this.block = block;
this.info = info;
this.drops = info.collectDrops(new LootBuilder(player, 0));
this.drops = (info.hasDropTable() && info.getDropTable().areConditionsMet(new ConditionInstance(player.getPlayer())))
? info.collectDrops(new LootBuilder(player, 0)) : new ArrayList<>();
this.experience = info.hasExperience() ? info.getExperience().newInfo() : null;
}

View File

@ -42,6 +42,6 @@ public abstract class SpecificExperienceSource<T> extends ExperienceSource<T> {
* Location used to display the exp hologram
*/
public void giveExperience(PlayerData player, int multiplier, Location loc) {
giveExperience(player, rollAmount() * multiplier, loc);
super.giveExperience(player, rollAmount() * multiplier, loc);
}
}

View File

@ -1,5 +1,6 @@
package net.Indyuce.mmocore.api.load;
import net.Indyuce.mmocore.api.droptable.condition.LevelCondition;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.api.block.BlockType;
@ -113,6 +114,9 @@ public class DefaultMMOLoader extends MMOLoader {
if (config.getKey().equals("biome"))
return new BiomeCondition(config);
if (config.getKey().equals("level"))
return new LevelCondition(config);
return null;
}

View File

@ -308,7 +308,7 @@ public class PlayerData extends OfflinePlayerData {
}
public boolean hasWaypoint(Waypoint waypoint) {
return waypoints.contains(waypoint.getId());
return waypoint.isDefault() || waypoints.contains(waypoint.getId());
}
public void unlockWaypoint(Waypoint waypoint) {

View File

@ -43,7 +43,7 @@ import net.mmogroup.mmolib.api.util.PostLoadObject;
import net.mmogroup.mmolib.version.VersionMaterial;
public class PlayerClass extends PostLoadObject {
private final String name, id;
private final String name, id, actionBarFormat;
private final List<String> description = new ArrayList<>(), attrDescription = new ArrayList<>();
private final ItemStack icon;
private final Map<ClassOption, Boolean> options = new HashMap<>();
@ -90,6 +90,7 @@ public class PlayerClass extends PostLoadObject {
: ManaDisplayOptions.DEFAULT;
maxLevel = config.getInt("max-level");
displayOrder = config.getInt("display.order");
actionBarFormat = config.contains("action-bar", true) ? config.getString("action-bar") : null;
expCurve = config.contains("exp-curve")
? MMOCore.plugin.experience.getOrThrow(
@ -185,6 +186,7 @@ public class PlayerClass extends PostLoadObject {
displayOrder = 0;
expCurve = ExpCurve.DEFAULT;
castParticle = new CastingParticle(Particle.SPELL_INSTANT);
actionBarFormat = "";
this.icon = new ItemStack(material);
setOption(ClassOption.DISPLAY, false);
@ -321,4 +323,12 @@ public class PlayerClass extends PostLoadObject {
public boolean equals(Object obj) {
return obj != null && obj instanceof PlayerClass && ((PlayerClass) obj).id.equals(id);
}
public String getActionBar() {
return actionBarFormat;
}
public boolean hasActionBar() {
return actionBarFormat != null;
}
}

View File

@ -91,8 +91,6 @@ public class ResetCommandTreeNode extends CommandTreeNode {
PlayerData data = PlayerData.get(player);
data.getWaypoints().clear();
MMOCore.plugin.waypointManager.getAll().stream().filter(waypoint -> waypoint.isDefault())
.forEach(waypoint -> data.unlockWaypoint(waypoint));
return CommandResult.SUCCESS;
}
}

View File

@ -18,7 +18,16 @@ import net.Indyuce.mmocore.api.quest.PlayerQuests;
import net.mmogroup.mmolib.api.util.AltChar;
public class RPGPlaceholders extends PlaceholderExpansion {
@Override
public boolean persist(){
return true;
}
@Override
public boolean canRegister(){
return true;
}
@Override
public String getAuthor() {
return "Indyuce";
@ -36,7 +45,6 @@ public class RPGPlaceholders extends PlaceholderExpansion {
@Override
public String onRequest(@Nullable OfflinePlayer player, @NotNull String identifier) {
if (identifier.equals("level"))
return "" + PlayerData.get(player).getLevel();

View File

@ -23,7 +23,6 @@ import net.Indyuce.mmocore.api.block.BlockInfo;
import net.Indyuce.mmocore.api.block.VanillaBlockType;
import net.Indyuce.mmocore.api.event.CustomBlockMineEvent;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions;
public class BlockListener implements Listener {
private static final BlockFace[] order = { BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH };
@ -62,13 +61,7 @@ public class BlockListener implements Listener {
}
ItemStack item = player.getInventory().getItemInMainHand();
BlockPermissions perms = MMOCore.plugin.restrictionManager.getPermissions(item.getType());
if (perms == null) {
event.setCancelled(true);
return;
}
if (!perms.canMine(info.getBlock())) {
if (!MMOCore.plugin.restrictionManager.checkPermissions(item, info.getBlock())) {
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
event.setCancelled(true);
return;

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmocore.listener;
import org.bukkit.Bukkit;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -47,7 +48,8 @@ public class PartyListener implements Listener {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void b(PlayerAttackEvent event) {
if (event.getEntity() instanceof Player) {
LivingEntity entity = event.getEntity();
if (entity instanceof Player && !entity.hasMetadata("NPC")) {
PlayerData targetData = PlayerData.get((Player) event.getEntity());
if (targetData.hasParty() && targetData.getParty().getMembers().has(event.getData().getMMOCore()))
event.setCancelled(true);

View File

@ -6,67 +6,85 @@ import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.block.BlockType;
import net.mmogroup.mmolib.api.MMOLineConfig;
import net.mmogroup.mmolib.api.itemtype.ItemType;
import net.mmogroup.mmolib.api.util.PostLoadObject;
public class RestrictionManager {
// private Set<String> breakBlackList = new HashSet<>();
private final Map<Material, BlockPermissions> map = new HashMap<>();
private final Map<ItemType, ToolPermissions> map = new HashMap<>();
public RestrictionManager(FileConfiguration config) {
for (String key : config.getKeys(false))
try {
register(new BlockPermissions(config.getConfigurationSection(key)));
register(new ToolPermissions(config.getConfigurationSection(key)));
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "Could not load block perms " + key + ": " + exception.getMessage());
}
for (BlockPermissions perms : map.values())
for (ToolPermissions perms : map.values())
try {
perms.postLoad();
} catch (IllegalArgumentException exception) {
MMOCore.log(Level.WARNING, "Could not load block perms " + perms.getTool().name() + ": " + exception.getMessage());
MMOCore.log(Level.WARNING, "Could not postload block perms " + perms.getTool().display() + ": " + exception.getMessage());
}
}
public void register(BlockPermissions perms) {
public void register(ToolPermissions perms) {
if (perms.isValid())
map.put(perms.getTool(), perms);
// perms.getMinable().forEach(material ->
// breakBlackList.add(material));
}
// public boolean isBlackListed(String s) {
// return breakBlackList.contains(s);
// }
public BlockPermissions getPermissions(Material tool) {
return map.getOrDefault(tool, null);
/**
* @param item
* The item used to break a block
* @return A list of all the blocks an item is allowed to break.
*/
public Set<ToolPermissions> getPermissions(ItemStack item) {
Set<ToolPermissions> set = new HashSet<>();
for (ItemType type : map.keySet())
if (type.matches(item))
set.add(map.get(type));
return set;
}
public class BlockPermissions extends PostLoadObject {
/**
* Performance method so that MMOCore does not have to fill in a set of
* toolPermission instances.
*
* @param item
* The item used to break a block
* @return If the block can be broken by a certain item
*/
public boolean checkPermissions(ItemStack item, BlockType block) {
for (ItemType type : map.keySet())
if (type.matches(item) && map.get(type).canMine(block))
return true;
return false;
}
public class ToolPermissions extends PostLoadObject {
private final Set<BlockType> mineable = new HashSet<>();
private final Material tool;
private final ItemType tool;
private BlockPermissions parent;
private ToolPermissions parent;
public BlockPermissions(ConfigurationSection config) {
public ToolPermissions(ConfigurationSection config) {
super(config);
tool = Material.valueOf(config.getName());
tool = ItemType.fromString(config.getName());
}
@Override
protected void whenPostLoaded(ConfigurationSection config) {
if (config.contains("parent"))
parent = map.get(Material.valueOf(config.getString("parent", "None").toUpperCase().replace("-", "_").replace(" ", "_")));
parent = map.get(ItemType.fromString(config.getString("parent")));
for (String key : config.getStringList("can-mine"))
mineable.add(MMOCore.plugin.loadManager.loadBlockType(new MMOLineConfig(key)));
}
@ -85,7 +103,7 @@ public class RestrictionManager {
return parent != null && parent.canMine(type);
}
public Material getTool() {
public ItemType getTool() {
return tool;
}

View File

@ -3,9 +3,7 @@ package net.Indyuce.mmocore.manager;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.stream.Collectors;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
@ -29,10 +27,6 @@ public class WaypointManager {
return waypoints.values();
}
public Set<Waypoint> getDefault() {
return getAll().stream().filter(waypoint -> waypoint.isDefault()).collect(Collectors.toSet());
}
public boolean has(String id) {
return waypoints.containsKey(id);
}

View File

@ -16,24 +16,29 @@ import net.Indyuce.mmocore.manager.data.yaml.YAMLGuildDataManager;
public class MySQLDataProvider implements DataProvider {
private final MySQLPlayerDataManager playerManager = new MySQLPlayerDataManager(this);
private final YAMLGuildDataManager guildManager = new YAMLGuildDataManager();
private final Connection connection;
private final MySQLConfig config;
private Connection connection;
public MySQLDataProvider() {
MySQLConfig config = new MySQLConfig(MMOCore.plugin.getConfig().getConfigurationSection("mysql"));
config = new MySQLConfig(MMOCore.plugin.getConfig().getConfigurationSection("mysql"));
initialize();
executeUpdate("CREATE TABLE IF NOT EXISTS mmocore_playerdata (uuid VARCHAR(36),class_points INT(11) DEFAULT 0,skill_points INT(11) DEFAULT 0,attribute_points INT(11) DEFAULT 0,attribute_realloc_points INT(11) DEFAULT 0,level INT(11) DEFAULT 0,experience INT(11) DEFAULT 0,class VARCHAR(20),guild VARCHAR(20),last_login LONG,attributes JSON,professions JSON,quests JSON,waypoints JSON,friends JSON,skills JSON,bound_skills JSON,class_info JSON,PRIMARY KEY (uuid));");
}
private void initialize() {
try {
Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(config.getConnectionString(), config.getUser(), config.getPassword());
} catch (ClassNotFoundException | SQLException exception) {
throw new IllegalArgumentException("Could not initialize MySQL support: " + exception.getMessage());
}
executeUpdate("CREATE TABLE IF NOT EXISTS mmocore_playerdata (uuid VARCHAR(36),class_points INT(11) DEFAULT 0,skill_points INT(11) DEFAULT 0,attribute_points INT(11) DEFAULT 0,attribute_realloc_points INT(11) DEFAULT 0,level INT(11) DEFAULT 0,experience INT(11) DEFAULT 0,class VARCHAR(20),guild VARCHAR(20),last_login LONG,attributes JSON,professions JSON,quests JSON,waypoints JSON,friends JSON,skills JSON,bound_skills JSON,class_info JSON,PRIMARY KEY (uuid));");
}
public ResultSet getResult(String sql) {
try {
return connection.prepareStatement(sql).executeQuery();
return getConnection().prepareStatement(sql).executeQuery();
} catch (SQLException exception) {
exception.printStackTrace();
return null;
@ -42,12 +47,23 @@ public class MySQLDataProvider implements DataProvider {
public void executeUpdate(String sql) {
try {
connection.prepareStatement(sql).executeUpdate();
getConnection().prepareStatement(sql).executeUpdate();
} catch (SQLException exception) {
exception.printStackTrace();
}
}
private Connection getConnection() {
try {
if(connection.isClosed())
initialize();
} catch (SQLException e) {
initialize();
}
return connection;
}
@Override
public PlayerDataManager getDataManager() {
return playerManager;

View File

@ -46,7 +46,6 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
data.getQuestData().updateBossBar();
if (config.contains("waypoints"))
data.getWaypoints().addAll(config.getStringList("waypoints"));
MMOCore.plugin.waypointManager.getDefault().forEach(waypoint -> data.getWaypoints().add(waypoint.getId()));
if (config.contains("friends"))
config.getStringList("friends").forEach(str -> data.getFriends().add(UUID.fromString(str)));
if (config.contains("skill"))