Skip to content

Commit

Permalink
Added player_consume, projectile_hit, and some new 1.5 abstraction.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Bilbrey committed Mar 21, 2013
1 parent ce1d63a commit 23ae407
Show file tree
Hide file tree
Showing 21 changed files with 389 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ public Velocity(double magnitude, double x, double y, double z) {
public boolean isEmpty();

public boolean isInsideVehicle();

public boolean isOnGround();

public boolean leaveVehicle();

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCLivingEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public interface MCLivingEntity extends MCEntity {
public void damage(int amount);
public void damage(int amount, MCEntity source);
public boolean getCanPickupItems();
public String getCustomName();
public MCEntityEquipment getEquipment();
public double getEyeHeight();
public double getEyeHeight(boolean ignoreSneaking);
Expand All @@ -36,9 +37,12 @@ public interface MCLivingEntity extends MCEntity {
public int getMaximumNoDamageTicks();
public int getNoDamageTicks();
public int getRemainingAir();
public boolean isCustomNameVisible();
public MCProjectile launchProjectile(MCProjectileType projectile);
public void resetMaxHealth();
public void setCanPickupItems(boolean pickup);
public void setCustomName(String name);
public void setCustomNameVisible(boolean visible);
public void setHealth(int health);
public void setLastDamage(int damage);
public void setMaxHealth(int health);
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import com.laytonsmith.abstraction.enums.MCInstrument;
import com.laytonsmith.abstraction.enums.MCSound;
import com.laytonsmith.abstraction.enums.MCWeatherType;

import java.net.InetSocketAddress;

Expand Down Expand Up @@ -40,6 +41,8 @@ public interface MCPlayer extends MCCommandSender, MCHumanEntity,

public long getPlayerTime();

public MCWeatherType getPlayerWeather();

public int getRemainingFireTicks();

public int getTotalExperience();
Expand All @@ -54,6 +57,8 @@ public interface MCPlayer extends MCCommandSender, MCHumanEntity,

public void resetPlayerTime();

public void resetPlayerWeather();

public void setAllowFlight(boolean flight);

public void setCompassTarget(MCLocation l);
Expand All @@ -70,6 +75,8 @@ public interface MCPlayer extends MCCommandSender, MCHumanEntity,

public void setPlayerTime(Long time);

public void setPlayerWeather(MCWeatherType type);

public void setRemainingFireTicks(int i);

public void setTempOp(Boolean value) throws Exception;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/laytonsmith/abstraction/MCWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public interface MCWorld extends AbstractionObject{

public MCItem dropItem(MCLocation l, MCItemStack is);

public void strikeLightning(MCLocation GetLocation);
public MCLightningStrike strikeLightning(MCLocation GetLocation);

public void strikeLightningEffect(MCLocation GetLocation);
public MCLightningStrike strikeLightningEffect(MCLocation GetLocation);

public void setStorm(boolean b);
public void setThundering(boolean b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ public boolean isEmpty() {
public boolean isInsideVehicle() {
return e.isInsideVehicle();
}

public boolean isOnGround() {
return e.isOnGround();
}

public boolean isLivingEntity() {
return e instanceof LivingEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,20 @@ public void setTarget(MCLivingEntity target, Target t) {
}
((Creature) le).setTarget(target == null ? null : ((BukkitMCLivingEntity) target).asLivingEntity());
}

public String getCustomName() {
return le.getCustomName();
}

public boolean isCustomNameVisible() {
return le.isCustomNameVisible();
}

public void setCustomName(String name) {
le.setCustomName(name);
}

public void setCustomNameVisible(boolean visible) {
le.setCustomNameVisible(visible);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.laytonsmith.abstraction.*;
import com.laytonsmith.abstraction.enums.MCInstrument;
import com.laytonsmith.abstraction.enums.MCSound;
import com.laytonsmith.abstraction.enums.MCWeatherType;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCInstrument;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCSound;
import com.laytonsmith.commandhelper.CommandHelperPlugin;
Expand All @@ -20,6 +21,7 @@
import org.bukkit.Location;
import org.bukkit.Note;
import org.bukkit.Server;
import org.bukkit.WeatherType;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
Expand Down Expand Up @@ -126,6 +128,10 @@ public long getPlayerTime() {
return p.getPlayerTime();
}

public MCWeatherType getPlayerWeather() {
return MCWeatherType.valueOf(p.getPlayerWeather().name());
}

public int getRemainingFireTicks() {
return p.getFireTicks();
}
Expand Down Expand Up @@ -222,6 +228,10 @@ public void resetPlayerTime() {
p.resetPlayerTime();
}

public void resetPlayerWeather() {
p.resetPlayerWeather();
}

public void sendMessage(String string) {
//The client doesn't like tabs
string = string.replaceAll("\t", " ");
Expand Down Expand Up @@ -267,6 +277,10 @@ public void setPlayerTime(Long time) {
p.setPlayerTime(time, false);
}

public void setPlayerWeather(MCWeatherType type) {
p.setPlayerWeather(WeatherType.valueOf(type.name()));
}

public void setRemainingFireTicks(int i) {
p.setFireTicks(i);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,15 @@ public MCItem dropItem(MCLocation l, MCItemStack is) {
return new BukkitMCItem(w.dropItem(((BukkitMCLocation) l).l, ((BukkitMCItemStack) is).is));
}

public void strikeLightning(MCLocation GetLocation) {
w.strikeLightning(((BukkitMCLocation) GetLocation).l);
}
public MCLightningStrike strikeLightning(MCLocation GetLocation) {
return new BukkitMCLightningStrike(
w.strikeLightning(((BukkitMCLocation) GetLocation).l));
}

public void strikeLightningEffect(MCLocation GetLocation) {
w.strikeLightningEffect(((BukkitMCLocation) GetLocation).l);
}
public MCLightningStrike strikeLightningEffect(MCLocation GetLocation) {
return new BukkitMCLightningStrike(
w.strikeLightningEffect(((BukkitMCLocation) GetLocation).l));
}

public void setStorm(boolean b) {
w.setStorm(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
package com.laytonsmith.abstraction.bukkit.events;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.laytonsmith.abstraction.*;
import com.laytonsmith.abstraction.bukkit.BukkitConvertor;
Expand All @@ -11,6 +13,7 @@
import com.laytonsmith.abstraction.bukkit.BukkitMCLivingEntity;
import com.laytonsmith.abstraction.bukkit.BukkitMCLocation;
import com.laytonsmith.abstraction.bukkit.BukkitMCPlayer;
import com.laytonsmith.abstraction.bukkit.BukkitMCProjectile;
import com.laytonsmith.abstraction.enums.MCDamageCause;
import com.laytonsmith.abstraction.enums.MCEntityType;
import com.laytonsmith.abstraction.enums.MCMobs;
Expand All @@ -29,6 +32,8 @@
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.PotionSplashEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
Expand All @@ -40,6 +45,66 @@
*/
public class BukkitEntityEvents {

@abstraction(type = Implementation.Type.BUKKIT)
public static class BukkitMCProjectileHitEvent implements MCProjectileHitEvent {

ProjectileHitEvent phe;
public BukkitMCProjectileHitEvent(ProjectileHitEvent event) {
phe = event;
}

public Object _GetObject() {
return phe;
}

public MCProjectile getEntity() {
return new BukkitMCProjectile(phe.getEntity());
}

public MCEntityType getEntityType() {
return MCEntityType.valueOf(phe.getEntityType().name());
}

public static BukkitMCProjectileHitEvent _instantiate(MCProjectile p) {
return new BukkitMCProjectileHitEvent(
new ProjectileHitEvent(
((BukkitMCProjectile) p).asProjectile()));
}

}

@abstraction(type = Implementation.Type.BUKKIT)
public static class BukkitMCPotionSplashEvent extends BukkitMCProjectileHitEvent
implements MCPotionSplashEvent {

PotionSplashEvent pse;
public BukkitMCPotionSplashEvent(PotionSplashEvent event) {
super(event);
pse = event;
}

public Object _GetObject() {
return pse;
}

public Set<MCLivingEntity> getAffectedEntities() {
Set<MCLivingEntity> ret = new HashSet<MCLivingEntity>();
for (LivingEntity le : pse.getAffectedEntities()) {
ret.add((MCLivingEntity) BukkitConvertor.BukkitGetCorrectEntity(le));
}
return ret;
}

public double getIntensity(MCLivingEntity le) {
return pse.getIntensity(((BukkitMCLivingEntity) le).asLivingEntity());
}

public void setIntensity(MCLivingEntity le, double intensity) {
pse.setIntensity(((BukkitMCLivingEntity) le).asLivingEntity(), intensity);
}

}

@abstraction(type = Implementation.Type.BUKKIT)
public static class BukkitMCEntityDeathEvent implements MCEntityDeathEvent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@
*/
public class BukkitPlayerEvents {

public static class BukkitMCPlayerItemConsumeEvent
implements MCPlayerItemConsumeEvent {
PlayerItemConsumeEvent pic;
public BukkitMCPlayerItemConsumeEvent(PlayerItemConsumeEvent event) {
pic = event;
}

public MCItemStack getItem() {
return new BukkitMCItemStack(pic.getItem());
}

public void setItem(MCItemStack item) {
pic.setItem(((BukkitMCItemStack) item).asItemStack());
}

public Object _GetObject() {
return pic;
}

public static BukkitMCPlayerItemConsumeEvent _instantiate(
MCPlayer player, MCItemStack item) {
return new BukkitMCPlayerItemConsumeEvent(
new PlayerItemConsumeEvent(((BukkitMCPlayer) player)._Player(),
((BukkitMCItemStack) item).asItemStack()));
}

}

public static class BukkitMCPlayerKickEvent implements MCPlayerKickEvent {
PlayerKickEvent e;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.event.entity.EntityTargetEvent;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.entity.ProjectileHitEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
Expand Down Expand Up @@ -92,4 +93,12 @@ public void onEntityDamage(EntityDamageEvent event) {
EventUtils.TriggerListener(Driver.ENTITY_DAMAGE, "entity_damage", ede);
}
}

@EventHandler(priority=EventPriority.LOWEST)
public void onPHit(ProjectileHitEvent event) {
BukkitEntityEvents.BukkitMCProjectileHitEvent phe =
new BukkitEntityEvents.BukkitMCProjectileHitEvent(event);
EventUtils.TriggerExternal(phe);
EventUtils.TriggerListener(Driver.PROJECTILE_HIT, "projectile_hit", phe);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,4 +198,12 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
EventUtils.TriggerListener(Driver.WORLD_CHANGED, "world_changed", wce);
}
}

@EventHandler(priority = EventPriority.LOWEST)
public void onConsume(PlayerItemConsumeEvent event) {
BukkitPlayerEvents.BukkitMCPlayerItemConsumeEvent pic =
new BukkitPlayerEvents.BukkitMCPlayerItemConsumeEvent(event);
EventUtils.TriggerExternal(pic);
EventUtils.TriggerListener(Driver.PLAYER_CONSUME, "player_consume", pic);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum MCInventoryType {
ENCHANTING,
ENDER_CHEST,
FURNACE,
HOPPER,
MERCHANT,
PLAYER,
WORKBENCH,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.laytonsmith.abstraction.enums;

public enum MCWeatherType {
CLEAR,
DOWNFALL
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.laytonsmith.abstraction.events;

import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.MCPlayer;
import com.laytonsmith.core.events.BindableEvent;

/**
*
* @author jb_aero
*/
public interface MCPlayerItemConsumeEvent extends BindableEvent {
public MCItemStack getItem();
public void setItem(MCItemStack item);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.laytonsmith.abstraction.events;

import java.util.Set;

import com.laytonsmith.abstraction.MCLivingEntity;

/**
*
* @author jb_aero
*/
public interface MCPotionSplashEvent extends MCProjectileHitEvent {
public Set<MCLivingEntity> getAffectedEntities();
public double getIntensity(MCLivingEntity le);
public void setIntensity(MCLivingEntity le, double intensity);
}
Loading

0 comments on commit 23ae407

Please sign in to comment.