Gamemode mixin

This commit is contained in:
BuildTools 2015-12-14 12:27:12 +01:00 committed by Olof Larsson
parent 00e297cceb
commit 9a78535f80
7 changed files with 100 additions and 1 deletions

View File

@ -29,6 +29,12 @@ public class TypeSenderEntity<T extends SenderEntity<T>> extends TypeSenderIdAbs
this.coll = coll;
}
private TypeSenderEntity(SenderColl<T> coll, SenderType type)
{
super(coll, type);
this.coll = coll;
}
private TypeSenderEntity(SenderColl<T> coll)
{
super(coll);
@ -41,6 +47,7 @@ public class TypeSenderEntity<T extends SenderEntity<T>> extends TypeSenderIdAbs
public static <T extends SenderEntity<T>> TypeSenderEntity<T> get(SenderColl<T> coll, SenderPresence presence, SenderType type) { return new TypeSenderEntity<T>(coll, presence, type); }
public static <T extends SenderEntity<T>> TypeSenderEntity<T> get(SenderColl<T> coll, SenderPresence presence) { return new TypeSenderEntity<T>(coll, presence); }
public static <T extends SenderEntity<T>> TypeSenderEntity<T> get(SenderColl<T> coll, SenderType type) { return new TypeSenderEntity<T>(coll, type); }
public static <T extends SenderEntity<T>> TypeSenderEntity<T> get(SenderColl<T> coll) { return new TypeSenderEntity<T>(coll); }
// -------------------------------------------- //

View File

@ -21,6 +21,13 @@ public class TypeSenderId extends TypeSenderIdAbstract<String>
super(source, presence);
}
private TypeSenderId(SenderIdSource source, SenderType type)
{
super(source, type);
}
private TypeSenderId(SenderIdSource source)
{
super(source);
@ -39,6 +46,7 @@ public class TypeSenderId extends TypeSenderIdAbstract<String>
public static TypeSenderId get(SenderIdSource source, SenderPresence presence, SenderType type) { return new TypeSenderId(source, presence, type); }
public static TypeSenderId get(SenderIdSource source, SenderPresence presence) { return new TypeSenderId(source, presence); }
public static TypeSenderId get(SenderIdSource source, SenderType type) { return new TypeSenderId(source, type); }
public static TypeSenderId get(SenderIdSource source) { return new TypeSenderId(source); }
// -------------------------------------------- //

View File

@ -15,6 +15,7 @@ import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.store.SenderIdSource;
import com.massivecraft.massivecore.util.IdUtil;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt;
public abstract class TypeSenderIdAbstract<T> extends TypeAbstract<T>
{
@ -46,6 +47,11 @@ public abstract class TypeSenderIdAbstract<T> extends TypeAbstract<T>
this(source, presence, SenderType.ANY);
}
public TypeSenderIdAbstract(SenderIdSource source, SenderType type)
{
this(source, SenderPresence.ANY, type);
}
public TypeSenderIdAbstract(SenderIdSource source)
{
this(source, SenderPresence.ANY);
@ -109,7 +115,7 @@ public abstract class TypeSenderIdAbstract<T> extends TypeAbstract<T>
if (ret == null)
{
// No alternatives found
throw new MassiveException().addMsg("<b>No %s matches \"<h>%s<b>\".", this.getTypeName(), arg);
throw new MassiveException().addMessage(this.getErrorMessageForArg(arg));
}
// Return Ret
@ -166,6 +172,11 @@ public abstract class TypeSenderIdAbstract<T> extends TypeAbstract<T>
// UTIL
// -------------------------------------------- //
public String getErrorMessageForArg(String arg)
{
return Txt.parse("<b>No %s matches \"<h>%s<b>\".", this.getTypeName(), arg);
}
public String getSenderIdFor(String arg)
{
// Get senderId from the arg.

View File

@ -0,0 +1,9 @@
package com.massivecraft.massivecore.mixin;
import org.bukkit.GameMode;
public interface GamemodeMixin
{
public GameMode getGamemode(Object playerObject);
public void setGamemode(Object playerObject, GameMode gm);
}

View File

@ -0,0 +1,6 @@
package com.massivecraft.massivecore.mixin;
public abstract class GamemodeMixinAbstract implements GamemodeMixin
{
}

View File

@ -0,0 +1,39 @@
package com.massivecraft.massivecore.mixin;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import com.massivecraft.massivecore.util.IdUtil;
public class GamemodeMixinDefault extends GamemodeMixinAbstract
{
// -------------------------------------------- //
// INSTANCE & CONSTRUCT
// -------------------------------------------- //
private static GamemodeMixinDefault i = new GamemodeMixinDefault();
public static GamemodeMixinDefault get() { return i; }
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public GameMode getGamemode(Object playerObject)
{
Player player = IdUtil.getPlayer(playerObject);
if (player == null) return null;
return player.getGameMode();
}
@Override
public void setGamemode(Object playerObject, GameMode gm)
{
Player player = IdUtil.getPlayer(playerObject);
if (player == null) return;
player.setGameMode(gm);
}
}

View File

@ -4,6 +4,7 @@ import java.util.Collection;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.command.CommandSender;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
@ -41,6 +42,10 @@ public class Mixin
private static SenderPsMixin senderPsMixin = SenderPsMixinDefault.get();
public static SenderPsMixin getSenderPsMixin() { return senderPsMixin; }
public static void setSenderPsMixin(SenderPsMixin val) { senderPsMixin = val; }
private static GamemodeMixin gamemodeMixin = GamemodeMixinDefault.get();
public static GamemodeMixin getGamemodeMixin() { return gamemodeMixin; }
public static void setGamemodeMixin(GamemodeMixin val) { gamemodeMixin = val; }
private static PlayedMixin playedMixin = PlayedMixinDefault.get();
public static PlayedMixin getPlayedMixin() { return playedMixin; }
@ -184,6 +189,20 @@ public class Mixin
getSenderPsMixin().setSenderPs(senderObject, ps);
}
// -------------------------------------------- //
// STATIC EXPOSE: GAMEMODE
// -------------------------------------------- //
public static GameMode getGamemode(Object playerObject)
{
return getGamemodeMixin().getGamemode(playerObject);
}
public static void setGamemode(Object playerObject, GameMode gm)
{
getGamemodeMixin().setGamemode(playerObject, gm);
}
// -------------------------------------------- //
// STATIC EXPOSE: PLAYED
// -------------------------------------------- //