mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-22 18:45:29 +01:00
Add GameModeTrait
This commit is contained in:
parent
f47912f001
commit
3ca12de138
@ -75,6 +75,7 @@ import net.citizensnpcs.trait.ArmorStandTrait;
|
||||
import net.citizensnpcs.trait.Controllable;
|
||||
import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.trait.FollowTrait;
|
||||
import net.citizensnpcs.trait.GameModeTrait;
|
||||
import net.citizensnpcs.trait.Gravity;
|
||||
import net.citizensnpcs.trait.HorseModifiers;
|
||||
import net.citizensnpcs.trait.LookClose;
|
||||
@ -564,7 +565,7 @@ public class NPCCommands {
|
||||
Messaging.sendErrorTr(sender, Messages.GAMEMODE_INVALID, args.getString(1));
|
||||
return;
|
||||
}
|
||||
player.setGameMode(mode);
|
||||
npc.getTrait(GameModeTrait.class).setGameMode(mode);
|
||||
Messaging.sendTr(sender, Messages.GAMEMODE_SET, mode.name().toLowerCase());
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,7 @@ import net.citizensnpcs.trait.ArmorStandTrait;
|
||||
import net.citizensnpcs.trait.Controllable;
|
||||
import net.citizensnpcs.trait.CurrentLocation;
|
||||
import net.citizensnpcs.trait.FollowTrait;
|
||||
import net.citizensnpcs.trait.GameModeTrait;
|
||||
import net.citizensnpcs.trait.Gravity;
|
||||
import net.citizensnpcs.trait.HorseModifiers;
|
||||
import net.citizensnpcs.trait.LookClose;
|
||||
@ -57,6 +58,7 @@ public class CitizensTraitFactory implements TraitFactory {
|
||||
registerTrait(TraitInfo.create(CurrentLocation.class));
|
||||
registerTrait(TraitInfo.create(Equipment.class));
|
||||
registerTrait(TraitInfo.create(FollowTrait.class));
|
||||
registerTrait(TraitInfo.create(GameModeTrait.class));
|
||||
registerTrait(TraitInfo.create(Gravity.class));
|
||||
registerTrait(TraitInfo.create(HorseModifiers.class));
|
||||
registerTrait(TraitInfo.create(Inventory.class));
|
||||
|
29
main/src/main/java/net/citizensnpcs/trait/GameModeTrait.java
Normal file
29
main/src/main/java/net/citizensnpcs/trait/GameModeTrait.java
Normal file
@ -0,0 +1,29 @@
|
||||
package net.citizensnpcs.trait;
|
||||
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import net.citizensnpcs.api.persistence.Persist;
|
||||
import net.citizensnpcs.api.trait.Trait;
|
||||
import net.citizensnpcs.api.trait.TraitName;
|
||||
|
||||
@TraitName("gamemodetrait")
|
||||
public class GameModeTrait extends Trait {
|
||||
@Persist
|
||||
private GameMode mode;
|
||||
|
||||
public GameModeTrait() {
|
||||
super("gamemodetrait");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (npc.isSpawned() && npc.getEntity() instanceof Player && mode != null) {
|
||||
((Player) npc.getEntity()).setGameMode(mode);
|
||||
}
|
||||
}
|
||||
|
||||
public void setGameMode(GameMode mode) {
|
||||
this.mode = mode;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user