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

View File

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

View File

@ -31,7 +31,7 @@ public class PlayerActionBar extends BukkitRunnable {
for (PlayerData data : PlayerData.getAll()) for (PlayerData data : PlayerData.getAll())
if (data.isOnline() && !data.getPlayer().isDead() && !data.isCasting() && data.canSeeActionBar()) { 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(), 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("{health}", digit.format(data.getPlayer().getHealth()))
.replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue())) .replace("{max_health}", "" + StatType.MAX_HEALTH.format(data.getPlayer().getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()))
.replace("{mana_icon}", data.getProfess().getManaDisplay().getIcon()) .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 interface BlockType {
public void place(Location loc, RegeneratingBlock regenerating); 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(); public String generateKey();
/* /**
* generateKey() determines if the block is handled by that block type, * GenerateKey() determines if the block is handled by that block type,
* breakRestrictions(Block) applies some extra break restrictions; returns TRUE * breakRestrictions(Block) applies some extra break restrictions; returns
* if the block can be broken * TRUE if the block can be broken
*/ */
public boolean breakRestrictions(Block block); public boolean breakRestrictions(Block block);
} }

View File

@ -5,6 +5,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; 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.apache.commons.lang.Validate;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -18,6 +20,7 @@ import net.mmogroup.mmolib.api.util.PostLoadObject;
public class DropTable extends PostLoadObject { public class DropTable extends PostLoadObject {
private final String id; private final String id;
private final Set<DropItem> drops = new LinkedHashSet<>(); private final Set<DropItem> drops = new LinkedHashSet<>();
private final Set<Condition> conditions = new LinkedHashSet<>();
public DropTable(ConfigurationSection config) { public DropTable(ConfigurationSection config) {
super(config); super(config);
@ -37,16 +40,24 @@ public class DropTable extends PostLoadObject {
*/ */
@Override @Override
protected void whenPostLoaded(ConfigurationSection config) { protected void whenPostLoaded(ConfigurationSection config) {
List<String> list = config.getStringList("items"); List<String> itemsList = config.getStringList("items");
Validate.notNull(list, "Could not find drop item list"); List<String> conditionsList = config.getStringList("conditions");
Validate.notNull(itemsList, "Could not find drop item list");
for (String key : list) for (String key : itemsList)
try { try {
drops.add(MMOCore.plugin.loadManager.loadDropItem(new MMOLineConfig(key))); drops.add(MMOCore.plugin.loadManager.loadDropItem(new MMOLineConfig(key)));
} catch (IllegalArgumentException exception) { } catch (IllegalArgumentException exception) {
MMOCore.plugin.getLogger().log(Level.WARNING, MMOCore.plugin.getLogger().log(Level.WARNING,
"Could not load drop item '" + key + "' from table '" + id + "': " + exception.getMessage()); "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() { public String getId() {
@ -69,4 +80,17 @@ public class DropTable extends PostLoadObject {
return builder.getLoot(); 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); super(config);
config.validate("name"); config.validate("name");
names = Arrays.asList(config.getString("name").split("\\,")); names = Arrays.asList(config.getString("name").toUpperCase().split("\\,"));
} }
@Override @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.MMOCore;
import net.Indyuce.mmocore.api.droptable.DropTable; import net.Indyuce.mmocore.api.droptable.DropTable;
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
import net.Indyuce.mmocore.api.loot.LootBuilder; import net.Indyuce.mmocore.api.loot.LootBuilder;
import net.mmogroup.mmolib.api.MMOLineConfig; import net.mmogroup.mmolib.api.MMOLineConfig;
@ -22,7 +23,8 @@ public class DropTableDropItem extends DropItem {
@Override @Override
public void collect(LootBuilder builder) { public void collect(LootBuilder builder) {
for (int j = 0; j < rollAmount(); j++) if (dropTable.areConditionsMet(new ConditionInstance(builder.getEntity().getPlayer())))
builder.addLoot(dropTable.collect(builder)); for (int j = 0; j < rollAmount(); j++)
builder.addLoot(dropTable.collect(builder));
} }
} }

View File

@ -1,7 +1,9 @@
package net.Indyuce.mmocore.api.event; package net.Indyuce.mmocore.api.event;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.Indyuce.mmocore.api.droptable.condition.ConditionInstance;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.event.Cancellable; import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
@ -27,7 +29,8 @@ public class CustomBlockMineEvent extends PlayerDataEvent implements Cancellable
this.block = block; this.block = block;
this.info = info; 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; 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 * Location used to display the exp hologram
*/ */
public void giveExperience(PlayerData player, int multiplier, Location loc) { 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; package net.Indyuce.mmocore.api.load;
import net.Indyuce.mmocore.api.droptable.condition.LevelCondition;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.api.block.BlockType; import net.Indyuce.mmocore.api.block.BlockType;
@ -113,6 +114,9 @@ public class DefaultMMOLoader extends MMOLoader {
if (config.getKey().equals("biome")) if (config.getKey().equals("biome"))
return new BiomeCondition(config); return new BiomeCondition(config);
if (config.getKey().equals("level"))
return new LevelCondition(config);
return null; return null;
} }

View File

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

View File

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

View File

@ -18,7 +18,16 @@ import net.Indyuce.mmocore.api.quest.PlayerQuests;
import net.mmogroup.mmolib.api.util.AltChar; import net.mmogroup.mmolib.api.util.AltChar;
public class RPGPlaceholders extends PlaceholderExpansion { public class RPGPlaceholders extends PlaceholderExpansion {
@Override
public boolean persist(){
return true;
}
@Override
public boolean canRegister(){
return true;
}
@Override @Override
public String getAuthor() { public String getAuthor() {
return "Indyuce"; return "Indyuce";
@ -36,7 +45,6 @@ public class RPGPlaceholders extends PlaceholderExpansion {
@Override @Override
public String onRequest(@Nullable OfflinePlayer player, @NotNull String identifier) { public String onRequest(@Nullable OfflinePlayer player, @NotNull String identifier) {
if (identifier.equals("level")) if (identifier.equals("level"))
return "" + PlayerData.get(player).getLevel(); 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.block.VanillaBlockType;
import net.Indyuce.mmocore.api.event.CustomBlockMineEvent; import net.Indyuce.mmocore.api.event.CustomBlockMineEvent;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.manager.RestrictionManager.BlockPermissions;
public class BlockListener implements Listener { public class BlockListener implements Listener {
private static final BlockFace[] order = { BlockFace.UP, BlockFace.DOWN, BlockFace.EAST, BlockFace.NORTH, BlockFace.WEST, BlockFace.SOUTH }; 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(); ItemStack item = player.getInventory().getItemInMainHand();
BlockPermissions perms = MMOCore.plugin.restrictionManager.getPermissions(item.getType()); if (!MMOCore.plugin.restrictionManager.checkPermissions(item, info.getBlock())) {
if (perms == null) {
event.setCancelled(true);
return;
}
if (!perms.canMine(info.getBlock())) {
MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player); MMOCore.plugin.configManager.getSimpleMessage("cannot-break").send(player);
event.setCancelled(true); event.setCancelled(true);
return; return;

View File

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

View File

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

View File

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

View File

@ -16,24 +16,29 @@ import net.Indyuce.mmocore.manager.data.yaml.YAMLGuildDataManager;
public class MySQLDataProvider implements DataProvider { public class MySQLDataProvider implements DataProvider {
private final MySQLPlayerDataManager playerManager = new MySQLPlayerDataManager(this); private final MySQLPlayerDataManager playerManager = new MySQLPlayerDataManager(this);
private final YAMLGuildDataManager guildManager = new YAMLGuildDataManager(); private final YAMLGuildDataManager guildManager = new YAMLGuildDataManager();
private final MySQLConfig config;
private final Connection connection;
private Connection connection;
public MySQLDataProvider() { 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 { try {
Class.forName("com.mysql.jdbc.Driver"); Class.forName("com.mysql.jdbc.Driver");
connection = DriverManager.getConnection(config.getConnectionString(), config.getUser(), config.getPassword()); connection = DriverManager.getConnection(config.getConnectionString(), config.getUser(), config.getPassword());
} catch (ClassNotFoundException | SQLException exception) { } catch (ClassNotFoundException | SQLException exception) {
throw new IllegalArgumentException("Could not initialize MySQL support: " + exception.getMessage()); 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) { public ResultSet getResult(String sql) {
try { try {
return connection.prepareStatement(sql).executeQuery(); return getConnection().prepareStatement(sql).executeQuery();
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
return null; return null;
@ -42,12 +47,23 @@ public class MySQLDataProvider implements DataProvider {
public void executeUpdate(String sql) { public void executeUpdate(String sql) {
try { try {
connection.prepareStatement(sql).executeUpdate(); getConnection().prepareStatement(sql).executeUpdate();
} catch (SQLException exception) { } catch (SQLException exception) {
exception.printStackTrace(); exception.printStackTrace();
} }
} }
private Connection getConnection() {
try {
if(connection.isClosed())
initialize();
} catch (SQLException e) {
initialize();
}
return connection;
}
@Override @Override
public PlayerDataManager getDataManager() { public PlayerDataManager getDataManager() {
return playerManager; return playerManager;

View File

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