2021-04-17 22:27:28 +02:00
|
|
|
/*
|
|
|
|
This file is a part of the SteamWar software.
|
|
|
|
|
|
|
|
Copyright (C) 2020 SteamWar.de-Serverteam
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU Affero General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
package de.steamwar.bausystem.entities;
|
2021-04-17 22:27:28 +02:00
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
import de.steamwar.bausystem.features.tracer.AbstractTraceEntity;
|
|
|
|
import de.steamwar.bausystem.shared.BaseEntity15;
|
2021-04-18 00:16:08 +02:00
|
|
|
import de.steamwar.bausystem.shared.ReferenceCounter;
|
|
|
|
import net.minecraft.server.v1_15_R1.ChatComponentText;
|
|
|
|
import org.bukkit.Material;
|
2021-04-17 22:27:28 +02:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.util.Vector;
|
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
public class TraceEntity15 extends BaseEntity15 implements AbstractTraceEntity {
|
2021-04-17 22:27:28 +02:00
|
|
|
|
|
|
|
private boolean exploded = false;
|
2021-04-18 00:16:08 +02:00
|
|
|
private ReferenceCounter referenceCounter = new ReferenceCounter();
|
2021-04-17 22:27:28 +02:00
|
|
|
|
2022-01-29 15:28:28 +01:00
|
|
|
public TraceEntity15(World world, Vector position, boolean tnt) {
|
2021-04-18 00:16:08 +02:00
|
|
|
super(world, position, tnt ? Material.TNT : Material.WHITE_STAINED_GLASS);
|
2021-04-17 22:27:28 +02:00
|
|
|
|
|
|
|
this.setNoGravity(true);
|
|
|
|
this.ticksLived = -12000;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-25 23:29:41 +01:00
|
|
|
public void display(Player player, boolean exploded, int ticks) {
|
|
|
|
if (ticks != -1) {
|
|
|
|
this.setCustomNameVisible(true);
|
|
|
|
this.setCustomName(new ChatComponentText(ticks + ""));
|
|
|
|
}
|
2021-04-17 22:27:28 +02:00
|
|
|
if (!this.exploded && exploded) {
|
|
|
|
this.setCustomNameVisible(true);
|
|
|
|
this.setCustomName(new ChatComponentText("Bumm"));
|
|
|
|
this.exploded = true;
|
2021-04-18 00:16:08 +02:00
|
|
|
if (referenceCounter.increment() > 0) {
|
2021-04-18 12:47:32 +02:00
|
|
|
sendEntityDestroy(player);
|
2021-04-18 00:16:08 +02:00
|
|
|
}
|
|
|
|
} else if (referenceCounter.increment() > 0) {
|
2021-04-17 22:27:28 +02:00
|
|
|
return;
|
2021-04-18 00:16:08 +02:00
|
|
|
}
|
2021-04-17 22:27:28 +02:00
|
|
|
|
2021-04-18 00:16:08 +02:00
|
|
|
sendEntity(player);
|
2021-04-17 22:27:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hide(Player player, boolean force) {
|
2021-04-18 00:16:08 +02:00
|
|
|
if (!force && referenceCounter.decrement() > 0) {
|
2021-04-17 22:27:28 +02:00
|
|
|
return false;
|
2021-04-18 00:16:08 +02:00
|
|
|
}
|
2021-04-17 22:27:28 +02:00
|
|
|
|
2021-04-18 12:47:32 +02:00
|
|
|
sendEntityDestroy(player);
|
2021-04-17 22:27:28 +02:00
|
|
|
die();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|