mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-01-29 19:41:50 +01:00
Add temporary testing character
This commit is contained in:
parent
ccf0b14547
commit
6972dba611
108
src/main/java/net/citizensnpcs/Derp.java
Normal file
108
src/main/java/net/citizensnpcs/Derp.java
Normal file
@ -0,0 +1,108 @@
|
||||
package net.citizensnpcs;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.citizensnpcs.api.ai.AI;
|
||||
import net.citizensnpcs.api.ai.AbstractGoal;
|
||||
import net.citizensnpcs.api.ai.Goal;
|
||||
import net.citizensnpcs.api.exception.NPCLoadException;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.Character;
|
||||
import net.citizensnpcs.api.trait.SaveId;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Arrow;
|
||||
|
||||
@SaveId("derp")
|
||||
public class Derp extends Character {
|
||||
@Override
|
||||
public void load(DataKey key) throws NPCLoadException {
|
||||
Messaging.log("load? derples!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(DataKey key) {
|
||||
Messaging.log("save? derpin' herp!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSet(final NPC npc) {
|
||||
AI ai = npc.getAI();
|
||||
final Random rand = new Random();
|
||||
ai.addGoal(0, new AbstractGoal() {
|
||||
@Override
|
||||
public void start() {
|
||||
npc.chat("derp time!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
Location loc = npc.getBukkitEntity().getLocation();
|
||||
loc.setPitch(new Random().nextFloat() * 360);
|
||||
loc.setYaw(new Random().nextFloat() * 360);
|
||||
npc.getBukkitEntity().teleport(loc);
|
||||
npc.move(rand.nextInt(3), rand.nextInt(3), rand.nextInt(3));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCompatibleWith(Goal other) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueExecuting() {
|
||||
return rand.nextInt(100) < 80;
|
||||
}
|
||||
});
|
||||
ai.addGoal(1, new AbstractGoal() {
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
int length = rand.nextInt(10);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int values = ChatColor.values().length;
|
||||
for (int i = 0; i <= length; ++i) {
|
||||
builder.append(ChatColor.values()[rand.nextInt(values)].toString() + getRandomChar());
|
||||
}
|
||||
npc.chat(builder.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean continueExecuting() {
|
||||
return rand.nextInt(100) < 60;
|
||||
}
|
||||
|
||||
private char getRandomChar() {
|
||||
int r = rand.nextInt(1000);
|
||||
while (!java.lang.Character.isDefined(r)) {
|
||||
r = rand.nextInt(1000);
|
||||
}
|
||||
return (char) r;
|
||||
}
|
||||
});
|
||||
ai.addGoal(2, new AbstractGoal() {
|
||||
|
||||
@Override
|
||||
public boolean continueExecuting() {
|
||||
return rand.nextInt(100) < 40;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
npc.chat("Firing away!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
Location loc = npc.getBukkitEntity().getLocation();
|
||||
loc.setPitch(new Random().nextFloat() * 360);
|
||||
loc.setYaw(new Random().nextFloat() * 360);
|
||||
npc.getBukkitEntity().teleport(loc);
|
||||
npc.getBukkitEntity().launchProjectile(Arrow.class);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import net.citizensnpcs.Settings.Setting;
|
||||
import net.citizensnpcs.api.npc.NPC;
|
||||
import net.citizensnpcs.api.trait.trait.Owner;
|
||||
import net.citizensnpcs.api.trait.trait.SpawnLocation;
|
||||
import net.citizensnpcs.editor.Editor;
|
||||
import net.citizensnpcs.npc.CitizensNPCManager;
|
||||
import net.citizensnpcs.resource.lib.EntityHumanNPC;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
@ -27,6 +28,7 @@ import org.bukkit.event.entity.EntityTargetEvent;
|
||||
import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.world.ChunkLoadEvent;
|
||||
import org.bukkit.event.world.ChunkUnloadEvent;
|
||||
import org.bukkit.event.world.WorldLoadEvent;
|
||||
@ -152,6 +154,11 @@ public class EventListen implements Listener {
|
||||
/*
|
||||
* Player events
|
||||
*/
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
Editor.leaveEditor(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteractEntity(PlayerInteractEntityEvent event) {
|
||||
if (!npcManager.isNPC(event.getRightClicked()))
|
||||
|
@ -1,10 +1,38 @@
|
||||
package net.citizensnpcs.editor;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public abstract class Editor implements Listener {
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
public abstract class Editor implements Listener {
|
||||
public abstract void begin();
|
||||
|
||||
public abstract void end();
|
||||
|
||||
public static void enterEditor(Player player, Editor editor) {
|
||||
if (editing.containsKey(player.getName())) {
|
||||
Messaging.sendError(player, "You're already in an editor!");
|
||||
return;
|
||||
}
|
||||
editor.begin();
|
||||
Bukkit.getPluginManager().registerEvents(editor, Bukkit.getPluginManager().getPlugin("Citizens"));
|
||||
editing.put(player.getName(), editor);
|
||||
}
|
||||
|
||||
public static void leaveEditor(Player player) {
|
||||
if (!editing.containsKey(player.getName()))
|
||||
return;
|
||||
Editor editor = editing.remove(player.getName());
|
||||
HandlerList.unregisterAll(editor);
|
||||
editor.end();
|
||||
}
|
||||
|
||||
private static final Map<String, Editor> editing = Maps.newHashMap();
|
||||
}
|
@ -10,7 +10,6 @@ import net.citizensnpcs.api.trait.trait.SpawnLocation;
|
||||
import net.citizensnpcs.api.trait.trait.Spawned;
|
||||
import net.citizensnpcs.npc.ai.CitizensAI;
|
||||
import net.citizensnpcs.util.Messaging;
|
||||
|
||||
import net.minecraft.server.EntityLiving;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
@ -43,6 +42,12 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
|
||||
protected abstract EntityLiving createHandle(Location loc);
|
||||
|
||||
@Override
|
||||
public void move(int x, int y, int z) {
|
||||
if (mcEntity != null)
|
||||
mcEntity.move(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean despawn() {
|
||||
if (!isSpawned()) {
|
||||
@ -82,8 +87,8 @@ public abstract class CitizensNPC extends AbstractNPC {
|
||||
if (isSpawned())
|
||||
despawn();
|
||||
manager.remove(this);
|
||||
((Citizens) Bukkit.getServer().getPluginManager().getPlugin("Citizens")).getStorage().getKey("npc").removeKey(
|
||||
String.valueOf(getId()));
|
||||
((Citizens) Bukkit.getServer().getPluginManager().getPlugin("Citizens")).getStorage().getKey("npc")
|
||||
.removeKey(String.valueOf(getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user