Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
106 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
main/src/main/java/net/citizensnpcs/trait/versioned/WardenTrait.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package net.citizensnpcs.trait.versioned; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.command.CommandSender; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.entity.EntityType; | ||
import org.bukkit.entity.Warden; | ||
|
||
import com.google.common.collect.Maps; | ||
|
||
import net.citizensnpcs.api.command.Arg; | ||
import net.citizensnpcs.api.command.Command; | ||
import net.citizensnpcs.api.command.CommandContext; | ||
import net.citizensnpcs.api.command.Requirements; | ||
import net.citizensnpcs.api.command.exception.CommandException; | ||
import net.citizensnpcs.api.command.exception.CommandUsageException; | ||
import net.citizensnpcs.api.npc.NPC; | ||
import net.citizensnpcs.api.trait.Trait; | ||
import net.citizensnpcs.api.trait.TraitName; | ||
import net.citizensnpcs.api.util.Messaging; | ||
|
||
@TraitName("wardentrait") | ||
public class WardenTrait extends Trait { | ||
private final Map<UUID, Integer> anger = Maps.newHashMap(); | ||
|
||
public WardenTrait() { | ||
super("wardentrait"); | ||
} | ||
|
||
private void addAnger(Entity entity, int anger) { | ||
this.anger.put(entity.getUniqueId(), anger); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
if (npc.isSpawned() && npc.getEntity() instanceof Warden) { | ||
Warden warden = (Warden) npc.getEntity(); | ||
for (Map.Entry<UUID, Integer> entry : anger.entrySet()) { | ||
warden.setAnger(Bukkit.getEntity(entry.getKey()), entry.getValue()); | ||
} | ||
} | ||
} | ||
|
||
@Command( | ||
aliases = { "npc" }, | ||
usage = "warden anger [entity uuid/player name] [anger]", | ||
desc = "Sets warden modifiers", | ||
modifiers = { "warden" }, | ||
min = 1, | ||
max = 4, | ||
permission = "citizens.npc.warden") | ||
@Requirements(selected = true, ownership = true, types = EntityType.WARDEN) | ||
public static void Warden(CommandContext args, CommandSender sender, NPC npc, | ||
@Arg(value = 1, completions = { "anger" }) String command, @Arg(2) String player, @Arg(3) Integer anger) | ||
throws CommandException { | ||
WardenTrait trait = npc.getOrAddTrait(WardenTrait.class); | ||
String output = ""; | ||
if (command.equalsIgnoreCase("anger")) { | ||
if (anger == null) | ||
throw new CommandUsageException(); | ||
Entity entity = null; | ||
try { | ||
UUID uuid = UUID.fromString(player); | ||
entity = Bukkit.getEntity(uuid); | ||
} catch (IllegalArgumentException iae) { | ||
entity = Bukkit.getOfflinePlayer(player).getPlayer(); | ||
} | ||
if (entity != null) { | ||
trait.addAnger(entity, anger); | ||
} | ||
} | ||
if (!output.isEmpty()) { | ||
Messaging.send(sender, output.trim()); | ||
} else { | ||
throw new CommandUsageException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters