2 * DemosceneMusic - UserAccessor.java - Copyright © 2012 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.demoscenemusic.template;
20 import net.pterodactylus.demoscenemusic.data.User;
21 import net.pterodactylus.util.template.Accessor;
22 import net.pterodactylus.util.template.ReflectionAccessor;
23 import net.pterodactylus.util.template.TemplateContext;
26 * {@link Accessor} implementation that extends the {@link User} by the
29 * <li><tt>god</tt> - returns {@code true} if the user’s level is
30 * {@link User#LEVEL_GOD} or higher.</li>
31 * <li><tt>user</tt> - returns {@code true} if the user’s level is
32 * {@link User#LEVEL_USER} or higher.</li>
35 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
37 public class UserAccessor extends ReflectionAccessor {
43 public Object get(TemplateContext templateContext, Object object, String member) {
44 User user = (User) object;
45 if ("god".equals(member)) {
46 return user.getLevel() >= User.LEVEL_GOD;
47 } else if ("user".equals(member)) {
48 return user.getLevel() >= User.LEVEL_USER;
50 return super.get(templateContext, object, member);