Cast to player in MoneyAction
This commit is contained in:
parent
b28d689cbd
commit
f93266135b
12
main/pom.xml
12
main/pom.xml
|
@ -1,5 +1,4 @@
|
|||
<!-- Citizens build file -->
|
||||
|
||||
<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>
|
||||
<parent>
|
||||
|
@ -8,7 +7,6 @@
|
|||
<version>2.0.30-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>citizens-main</artifactId>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<craftbukkit.version>1.19.2-R0.1-SNAPSHOT</craftbukkit.version>
|
||||
|
@ -17,7 +15,6 @@
|
|||
<worldguard.version>7.0.4</worldguard.version>
|
||||
<powermock.version>1.4.12</powermock.version>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
|
@ -47,7 +44,6 @@
|
|||
<url>https://repo.alessiodp.com/releases/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
|
@ -129,7 +125,6 @@
|
|||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<url>http://www.citizensnpcs.co</url>
|
||||
<ciManagement>
|
||||
<system>jenkins</system>
|
||||
|
@ -143,7 +138,6 @@
|
|||
<build>
|
||||
<defaultGoal>clean package install javadoc:javadoc</defaultGoal>
|
||||
<sourceDirectory>${basedir}/src/main/java</sourceDirectory>
|
||||
|
||||
<resources>
|
||||
<resource>
|
||||
<targetPath>.</targetPath>
|
||||
|
@ -155,7 +149,6 @@
|
|||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
@ -168,7 +161,6 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
@ -178,13 +170,11 @@
|
|||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
|
@ -232,7 +222,6 @@
|
|||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
|
@ -246,7 +235,6 @@
|
|||
<link>https://hub.spigotmc.org/javadocs/spigot</link>
|
||||
</links>
|
||||
<includeDependencySources>true</includeDependencySources>
|
||||
|
||||
<dependencySourceIncludes>
|
||||
<dependencySourceInclude>net.citizensnpcs:citizensapi</dependencySourceInclude>
|
||||
</dependencySourceIncludes>
|
||||
|
|
|
@ -2,8 +2,8 @@ package net.citizensnpcs.trait;
|
|||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
@ -24,7 +24,6 @@ import org.bukkit.inventory.ItemStack;
|
|||
import org.bukkit.permissions.PermissionAttachment;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
|
@ -234,13 +233,8 @@ public class CommandTrait extends Trait {
|
|||
|
||||
@Override
|
||||
public void run() {
|
||||
List<NPCCommand> commandList = Lists
|
||||
.newArrayList(Iterables.filter(commands.values(), new Predicate<NPCCommand>() {
|
||||
@Override
|
||||
public boolean apply(NPCCommand command) {
|
||||
return command.hand == hand || command.hand == Hand.BOTH;
|
||||
}
|
||||
}));
|
||||
List<NPCCommand> commandList = Lists.newArrayList(Iterables.filter(commands.values(),
|
||||
command -> command.hand == hand || command.hand == Hand.BOTH));
|
||||
if (executionMode == ExecutionMode.RANDOM) {
|
||||
if (commandList.size() > 0) {
|
||||
runCommand(player, commandList.get(Util.getFastRandom().nextInt(commandList.size())));
|
||||
|
@ -249,12 +243,7 @@ public class CommandTrait extends Trait {
|
|||
}
|
||||
int max = -1;
|
||||
if (executionMode == ExecutionMode.SEQUENTIAL) {
|
||||
Collections.sort(commandList, new Comparator<NPCCommand>() {
|
||||
@Override
|
||||
public int compare(NPCCommand o1, NPCCommand o2) {
|
||||
return Integer.compare(o1.id, o2.id);
|
||||
}
|
||||
});
|
||||
Collections.sort(commandList, (o1, o2) -> Integer.compare(o1.id, o2.id));
|
||||
max = commandList.size() > 0 ? commandList.get(commandList.size() - 1).id : -1;
|
||||
}
|
||||
if (executionMode == ExecutionMode.LINEAR) {
|
||||
|
@ -283,33 +272,30 @@ public class CommandTrait extends Trait {
|
|||
}
|
||||
|
||||
private void runCommand(final Player player, NPCCommand command) {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PlayerNPCCommand info = playerTracking.get(player.getUniqueId());
|
||||
if (info == null && (executionMode == ExecutionMode.SEQUENTIAL
|
||||
|| PlayerNPCCommand.requiresTracking(command))) {
|
||||
playerTracking.put(player.getUniqueId(), info = new PlayerNPCCommand());
|
||||
}
|
||||
if (info != null && !info.canUse(CommandTrait.this, player, command)) {
|
||||
Runnable runnable = () -> {
|
||||
PlayerNPCCommand info = playerTracking.get(player.getUniqueId());
|
||||
if (info == null && (executionMode == ExecutionMode.SEQUENTIAL
|
||||
|| PlayerNPCCommand.requiresTracking(command))) {
|
||||
playerTracking.put(player.getUniqueId(), info = new PlayerNPCCommand());
|
||||
}
|
||||
if (info != null && !info.canUse(CommandTrait.this, player, command)) {
|
||||
return;
|
||||
}
|
||||
if (charged == null) {
|
||||
if (!chargeCommandCosts(player, hand)) {
|
||||
charged = false;
|
||||
return;
|
||||
}
|
||||
if (charged == null) {
|
||||
if (!chargeCommandCosts(player, hand)) {
|
||||
charged = false;
|
||||
return;
|
||||
}
|
||||
charged = true;
|
||||
}
|
||||
PermissionAttachment attachment = player.addAttachment(CitizensAPI.getPlugin());
|
||||
if (temporaryPermissions.size() > 0) {
|
||||
for (String permission : temporaryPermissions) {
|
||||
attachment.setPermission(permission, true);
|
||||
}
|
||||
}
|
||||
command.run(npc, player);
|
||||
attachment.remove();
|
||||
charged = true;
|
||||
}
|
||||
PermissionAttachment attachment = player.addAttachment(CitizensAPI.getPlugin());
|
||||
if (temporaryPermissions.size() > 0) {
|
||||
for (String permission : temporaryPermissions) {
|
||||
attachment.setPermission(permission, true);
|
||||
}
|
||||
}
|
||||
command.run(npc, player);
|
||||
attachment.remove();
|
||||
};
|
||||
if (command.delay <= 0) {
|
||||
runnable.run();
|
||||
|
@ -360,8 +346,12 @@ public class CommandTrait extends Trait {
|
|||
@Override
|
||||
public void save(DataKey key) {
|
||||
Collection<NPCCommand> commands = this.commands.values();
|
||||
for (PlayerNPCCommand playerCommand : playerTracking.values()) {
|
||||
for (Iterator<PlayerNPCCommand> itr = playerTracking.values().iterator(); itr.hasNext();) {
|
||||
PlayerNPCCommand playerCommand = itr.next();
|
||||
playerCommand.prune(globalCooldowns, commands);
|
||||
if (playerCommand.lastUsed.isEmpty() && playerCommand.nUsed.isEmpty() && playerCommand.lastUsedId == -1) {
|
||||
itr.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,8 +4,8 @@ import java.util.function.Consumer;
|
|||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import net.citizensnpcs.api.gui.InputMenus;
|
||||
|
@ -14,7 +14,7 @@ import net.citizensnpcs.api.persistence.Persist;
|
|||
import net.citizensnpcs.util.Util;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
public class MoneyAction extends NPCShopAction {
|
||||
public class MoneyAction extends NPCShopAction {
|
||||
@Persist
|
||||
public double money;
|
||||
|
||||
|
@ -23,10 +23,10 @@ public class MoneyAction extends NPCShopAction {
|
|||
|
||||
@Override
|
||||
public Transaction grant(Entity entity) {
|
||||
if (!(entity instanceof OfflinePlayer))
|
||||
if (!(entity instanceof Player))
|
||||
return Transaction.fail();
|
||||
Economy economy = Bukkit.getServicesManager().getRegistration(Economy.class).getProvider();
|
||||
OfflinePlayer player = (OfflinePlayer) entity;
|
||||
Player player = (Player) entity;
|
||||
return Transaction.create(() -> {
|
||||
return true;
|
||||
}, () -> {
|
||||
|
@ -38,10 +38,10 @@ public class MoneyAction extends NPCShopAction {
|
|||
|
||||
@Override
|
||||
public Transaction take(Entity entity) {
|
||||
if (!(entity instanceof OfflinePlayer))
|
||||
if (!(entity instanceof Player))
|
||||
return Transaction.fail();
|
||||
Economy economy = Bukkit.getServicesManager().getRegistration(Economy.class).getProvider();
|
||||
OfflinePlayer player = (OfflinePlayer) entity;
|
||||
Player player = (Player) entity;
|
||||
return Transaction.create(() -> {
|
||||
return economy.has(player, money);
|
||||
}, () -> {
|
||||
|
|
Loading…
Reference in New Issue