use of org.bukkit.entity.Player in project Denizen-For-Bukkit by DenizenScript.
the class DenizenCommand method canSeeHelp.
public boolean canSeeHelp(CommandSender commandSender) {
if (!script.hasAllowedHelpProcedure()) {
return true;
}
if (!testPermissionSilent(commandSender)) {
return false;
}
Map<String, dObject> context = new HashMap<String, dObject>();
dPlayer player = null;
dNPC npc = null;
if (commandSender instanceof Player) {
Player pl = (Player) commandSender;
if (!dEntity.isNPC(pl)) {
player = dPlayer.mirrorBukkitPlayer(pl);
}
context.put("server", Element.FALSE);
} else {
context.put("server", Element.TRUE);
}
return script.runAllowedHelpProcedure(player, npc, context);
}
use of org.bukkit.entity.Player in project Denizen-For-Bukkit by DenizenScript.
the class ProximityTrigger method onEnable.
@Override
public void onEnable() {
Bukkit.getServer().getPluginManager().registerEvents(this, DenizenAPI.getCurrentInstance());
final ProximityTrigger trigger = this;
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(), new Runnable() {
@Override
public void run() {
//
// Iterate over all of the NPCs
//
Iterator<dNPC> it = dNPCRegistry.getSpawnedNPCs().iterator();
while (it.hasNext()) {
dNPC npc = it.next();
if (npc == null) {
continue;
}
if (npc.getCitizen() == null) {
continue;
}
//
if (!npc.getCitizen().hasTrait(TriggerTrait.class)) {
continue;
}
if (!npc.getCitizen().getTrait(TriggerTrait.class).isEnabled(name)) {
continue;
}
if (!npc.isSpawned()) {
continue;
}
// Loop through all players
for (Player BukkitPlayer : Bukkit.getOnlinePlayers()) {
//
if (!npc.getWorld().equals(BukkitPlayer.getWorld()) && hasExitedProximityOf(BukkitPlayer, npc)) {
continue;
}
//
if (!isCloseEnough(BukkitPlayer, npc) && hasExitedProximityOf(BukkitPlayer, npc)) {
continue;
}
// Get the player
dPlayer player = dPlayer.mirrorBukkitPlayer(BukkitPlayer);
//
// Check to make sure the NPC has an assignment. If no assignment, a script doesn't need to be parsed,
// but it does still need to trigger for cooldown and action purposes.
//
InteractScriptContainer script = npc.getInteractScriptQuietly(player, ProximityTrigger.class);
//
// Set default ranges with information from the TriggerTrait. This allows per-npc overrides and will
// automatically check the config for defaults.
//
double entryRadius = npc.getTriggerTrait().getRadius(name);
double exitRadius = npc.getTriggerTrait().getRadius(name);
double moveRadius = npc.getTriggerTrait().getRadius(name);
//
if (script != null) {
try {
if (script.hasTriggerOptionFor(ProximityTrigger.class, player, null, "ENTRY RADIUS")) {
entryRadius = Integer.valueOf(script.getTriggerOptionFor(ProximityTrigger.class, player, null, "ENTRY RADIUS"));
}
} catch (NumberFormatException nfe) {
dB.echoDebug(script, "Entry Radius was not an integer. Assuming " + entryRadius + " as the radius.");
}
try {
if (script.hasTriggerOptionFor(ProximityTrigger.class, player, null, "EXIT RADIUS")) {
exitRadius = Integer.valueOf(script.getTriggerOptionFor(ProximityTrigger.class, player, null, "EXIT RADIUS"));
}
} catch (NumberFormatException nfe) {
dB.echoDebug(script, "Exit Radius was not an integer. Assuming " + exitRadius + " as the radius.");
}
try {
if (script.hasTriggerOptionFor(ProximityTrigger.class, player, null, "MOVE RADIUS")) {
moveRadius = Integer.valueOf(script.getTriggerOptionFor(ProximityTrigger.class, player, null, "MOVE RADIUS"));
}
} catch (NumberFormatException nfe) {
dB.echoDebug(script, "Move Radius was not an integer. Assuming " + moveRadius + " as the radius.");
}
}
Location npcLocation = npc.getLocation();
//
// If the Player switches worlds while in range of an NPC, trigger still needs to
// fire since technically they have exited proximity. Let's check that before
// trying to calculate a distance between the Player and NPC, which will throw
// an exception if worlds do not match.
//
boolean playerChangedWorlds = false;
if (npcLocation.getWorld() != player.getWorld()) {
playerChangedWorlds = true;
}
//
// If the user is outside the range, and was previously within the
// range, then execute the "Exit" script.
//
// If the user entered the range and were not previously within the
// range, then execute the "Entry" script.
//
// If the user was previously within the range and moved, then execute
// the "Move" script.
//
boolean exitedProximity = hasExitedProximityOf(BukkitPlayer, npc);
double distance = 0;
if (!playerChangedWorlds) {
distance = npcLocation.distance(player.getLocation());
}
if (!exitedProximity && (playerChangedWorlds || distance >= exitRadius)) {
if (!npc.getTriggerTrait().triggerCooldownOnly(trigger, player)) {
continue;
}
// Remember that NPC has exited proximity.
exitProximityOf(BukkitPlayer, npc);
// Exit Proximity Action
npc.action("exit proximity", player);
// Parse Interact Script
parse(npc, player, script, "EXIT");
} else if (exitedProximity && distance <= entryRadius) {
// Cooldown
if (!npc.getTriggerTrait().triggerCooldownOnly(trigger, player)) {
continue;
}
// Remember that Player has entered proximity of the NPC
enterProximityOf(BukkitPlayer, npc);
// Enter Proximity Action
npc.action("enter proximity", player);
// Parse Interact Script
parse(npc, player, script, "ENTRY");
} else if (!exitedProximity && distance <= moveRadius) {
// TODO: Remove this? Constantly cooling down on move may make
// future entry/exit proximities 'lag' behind. Temporarily removing
// cooldown on 'move proximity'.
// if (!npc.getTriggerTrait().triggerCooldownOnly(this, event.getPlayer()))
// continue;
// Move Proximity Action
npc.action("move proximity", player);
// Parse Interact Script
parse(npc, player, script, "MOVE");
}
}
}
}
}, 5, 5);
}
use of org.bukkit.entity.Player in project Denizen-For-Bukkit by DenizenScript.
the class CommandContext method parseLocation.
public static Location parseLocation(Location currentLocation, String flag) throws CommandException {
boolean denizen = flag.startsWith("l@");
String[] parts = flag.replaceFirst("l@", "").split("[,]|[:]");
if (parts.length > 0) {
String worldName = currentLocation != null ? currentLocation.getWorld().getName() : "";
double x = 0, y = 0, z = 0;
float yaw = 0F, pitch = 0F;
switch(parts.length) {
case 6:
if (denizen) {
worldName = parts[5].replaceFirst("w@", "");
} else {
pitch = Float.parseFloat(parts[5]);
}
case 5:
if (denizen) {
pitch = Float.parseFloat(parts[4]);
} else {
yaw = Float.parseFloat(parts[4]);
}
case 4:
if (denizen && parts.length > 4) {
yaw = Float.parseFloat(parts[3]);
} else {
worldName = parts[3].replaceFirst("w@", "");
}
case 3:
x = Double.parseDouble(parts[0]);
y = Double.parseDouble(parts[1]);
z = Double.parseDouble(parts[2]);
break;
default:
throw new CommandException("Location could not be parsed or was not found.");
}
World world = Bukkit.getWorld(worldName);
if (world == null) {
throw new CommandException("Location could not be parsed or was not found.");
}
return new Location(world, x, y, z, yaw, pitch);
} else {
Player search = Bukkit.getPlayerExact(flag);
if (search == null) {
throw new CommandException("No player could be found by that name.");
}
return search.getLocation();
}
}
use of org.bukkit.entity.Player in project Denizen-For-Bukkit by DenizenScript.
the class Utilities method talkToNPC.
/**
* @param player the player doing the talking
* @param npc the npc being talked to
* @param range the range, in blocks, that 'bystanders' will hear he chat
*/
public static void talkToNPC(String message, dPlayer player, dNPC npc, double range) {
String replacer = String.valueOf((char) 0x04);
// Get formats from Settings, and fill in <TEXT>
String talkFormat = Settings.chatToNpcFormat().replaceAll("(?i)<TEXT>", replacer);
String bystanderFormat = Settings.chatToNpcOverheardFormat().replaceAll("(?i)<TEXT>", replacer);
// Fill in tags // TODO: Debug option?
talkFormat = TagManager.tag(talkFormat, new BukkitTagContext(player, npc, false, null, true, null)).replace(replacer, message);
bystanderFormat = TagManager.tag(bystanderFormat, new BukkitTagContext(player, npc, false, null, true, null)).replace(replacer, message);
// Send message to player
player.getPlayerEntity().sendMessage(talkFormat);
// Send message to bystanders
for (Player target : Bukkit.getOnlinePlayers()) {
if (target != player.getPlayerEntity()) {
if (target.getWorld().equals(player.getPlayerEntity().getWorld()) && target.getLocation().distance(player.getPlayerEntity().getLocation()) <= range) {
target.sendMessage(bystanderFormat);
}
}
}
}
use of org.bukkit.entity.Player in project Denizen-For-Bukkit by DenizenScript.
the class NPCTags method navBegin.
// <--[event]
// @Events
// npc begins navigation
//
// @Warning This event may fire very rapidly.
//
// @Triggers when an NPC begins navigating.
//
// @Context
// None
//
// -->
// <--[action]
// @Actions
// begin navigation
//
// @Triggers when the NPC has received a 'walk' command,
// or is about to follow a path.
//
// @Context
// None
//
// -->
@EventHandler
public void navBegin(NavigationBeginEvent event) {
dNPC npc = DenizenAPI.getDenizenNPC(event.getNPC());
// Do world script event 'On NPC Completes Navigation'
if (NPCNavigationSmartEvent.IsActive()) {
OldEventManager.doEvents(Arrays.asList("npc begins navigation"), new BukkitScriptEntryData(null, npc), null);
}
if (!event.getNPC().hasTrait(AssignmentTrait.class)) {
return;
}
npc.action("begin navigation", null);
if (event.getNPC().getNavigator().getTargetType() == TargetType.ENTITY) {
LivingEntity entity = (LivingEntity) event.getNPC().getNavigator().getEntityTarget().getTarget();
// and that entity is not dead, trigger "on attack" command
if (event.getNPC().getNavigator().getEntityTarget().isAggressive() && !entity.isDead()) {
dPlayer player = null;
// Check if the entity attacked by this NPC is a player
if (entity instanceof Player) {
player = dPlayer.mirrorBukkitPlayer((Player) entity);
}
// <--[action]
// @Actions
// attack
// attack on <entity>
//
// @Triggers when the NPC is about to attack an enemy.
//
// @Context
// None
//
// -->
npc.action("attack", player);
npc.action("attack on " + entity.getType().toString(), player);
}
previousLocations.put(event.getNPC().getId(), npc.getLocation());
}
}
Aggregations