001/* 002 * Trident - A Multithreaded Server Alternative 003 * Copyright 2014 The TridentSDK Team 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018package net.tridentsdk.server.entity.projectile; 019 020import net.tridentsdk.base.Position; 021import net.tridentsdk.entity.Projectile; 022import net.tridentsdk.entity.living.ProjectileLauncher; 023import net.tridentsdk.entity.traits.EntityProperties; 024import net.tridentsdk.server.entity.TridentEntity; 025 026import java.lang.ref.WeakReference; 027import java.util.UUID; 028 029/** 030 * Represents an entity that is thrown or launched 031 * 032 * @author The TridentSDK Team 033 */ 034public abstract class TridentProjectile extends TridentEntity implements Projectile { 035 /** 036 * The source that fires the projectile 037 */ 038 protected volatile WeakReference<ProjectileLauncher> source; 039 040 /** 041 * Inherits UUID and spawnPosition from {@link TridentEntity} 042 * 043 * @param source the entity which fired the projectile 044 */ 045 public TridentProjectile(UUID uniqueId, Position spawnLocation, ProjectileLauncher source) { 046 super(uniqueId, spawnLocation); 047 this.source = new WeakReference<>(source); 048 } 049 050 @Override 051 public boolean isNameVisible() { 052 return false; 053 } 054 055 @Override 056 public abstract void applyProperties(EntityProperties properties); 057 058 @Override 059 protected void doTick() { 060 // TODO 061 } 062 063 @Override 064 public void doHit() { 065 this.hit(); 066 } 067 068 /** 069 * Performed when the projectile hits something 070 */ 071 protected abstract void hit(); 072 073 @Override 074 public ProjectileLauncher launcher() { 075 return this.source.get(); 076 } 077 078 @Override 079 public void setLauncher(final ProjectileLauncher shooter) { 080 TridentProjectile.this.source = new WeakReference<>(shooter); 081 } 082}