public List<Object> findNearbyGangs(double lat, double lng, double distance) {
Query query = this.entityManager.createNativeQuery("SELECT id, (6371 * acos (cos(radians(:latitude)) * cos(radians(latitude)) * cos(radians(longitude) - radians(:longitude)) + sin(radians(:latitude)) * sin(radians(latitude)))) AS distance FROM Gang g GROUP BY id HAVING distance < :distance ORDER BY distance")
.setParameter("latitude", lat)
.setParameter("longitude", lng)
.setParameter("distance", distance);
List<Object> objects = query.getResultList();
return objects;
}
public class PasswordCommand extends PlayerCommand {
public PasswordCommand() {
super("Set Group Password");
setDescription("Sets the password for a group. Set password to \"null\" to make your group not joinable");
setUsage("/ctpassword §8<group-name> <password>");
setArgumentRange(2,2);
setIdentifiers(new String[] {"ctpassword", "ctpw"});
}
public boolean execute(CommandSender sender, String[] args) {
String groupName = args[0];
GroupManager groupManager = Citadel.getGroupManager();
Faction group = groupManager.getGroup(groupName);
if(group == null){
sendMessage(sender, ChatColor.RED, "Group doesn't exist");
return true;
}
String playerName = sender.getName();
if(!group.isFounder(playerName)){
sendMessage(sender, ChatColor.RED, "Invalid permission to modify this group");
return true;
}
String password = args[1];
if(password.isEmpty() || password.equals("")){
sendMessage(sender, ChatColor.RED, "Please enter a password");
return true;
}
group.setPassword(password);
groupManager.addGroup(group);
sendMessage(sender, ChatColor.GREEN, "Changed password for %s to \"%s\"", groupName, password);
return true;
}
}
Notice the following:
super("Set Group Password");
setDescription("Sets the password for a group. Set password to \"null\" to make your group not joinable");
setUsage("/ctpassword §8<group-name> <password>");
setArgumentRange(2,2);
setIdentifiers(new String[] {"ctpassword", "ctpw"});
If there are parameters missing it will return a message from the information provided in the code above. Notice in CommandHandler:
displayCommandHelp(cmd, sender);
Next we instantiate the commands in the singleton or main file called Citadel:
/**
* GET /greets-by-user/:groupId : get all the greets by group.
*
* @return the ResponseEntity with status 200 (OK) and the list of greets in body
*/
@GetMapping("/greets-by-group/{groupId}")
@Timed
public Object getAllGreetsByGroup(@PathVariable Long groupId) {
log.debug("REST request to get all Greets by user");
List<Greet> greets = greetService.getByGang(groupId);
Optional<Gang> optionalGang = this.gangService.getById(groupId);
Gang gang = optionalGang.get();
CanViewGang canViewGang = new CanViewGang(this.userService);
if (!canViewGang.isSatisfiedBy(gang)) {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);
}
CanViewGreetsByGang canViewGreetsByGang = new CanViewGreetsByGang(this.userRepository);
List<Greet> greetsToShow = new ArrayList<Greet>();
for (Greet greet : greets) {
if (canViewGreetsByGang.isSatisfiedBy(greet)) {
greetsToShow.add(greet);
}
}
return greetsToShow;
}
public class CanViewGreetsByGang extends AbstractSpecification<Greet> {
private User loggedInUser;
public CanViewGreetsByGang(UserRepository userRepository) {
Optional<String> login = SecurityUtils.getCurrentUserLogin();
this.loggedInUser = userRepository.findOneByLogin(login.get()).get();
}
public boolean isSatisfiedBy(Greet greet) {
IsGangPublic isGangPublic = new IsGangPublic();
IsHostOfGreet isHostOfGreet = new IsHostOfGreet(this.loggedInUser);
IsMemberOfGang isMemberOfGang = new IsMemberOfGang(this.loggedInUser);
boolean isGangPublicOrIsMemberOfGangBoolean = isGangPublic
.or(isMemberOfGang)
.isSatisfiedBy(greet.getGang());
boolean isHostOfGreetBoolean = isHostOfGreet
.isSatisfiedBy(greet);
return isGangPublicOrIsMemberOfGangBoolean || isHostOfGreetBoolean;
}
}
public String first(String text) {
return text.substring(0, 1);
}
@EventHandler(priority = EventPriority.HIGHEST)
public void blockPlace(BlockPlaceEvent bpe)
{
// Block placed by player
Block block = bpe.getBlock();
// Get the blocks material relative to the block placed by the player
Material main = block.getType();
Material up1 = block.getRelative(BlockFace.UP, 1).getType();
Material up2 = block.getRelative(BlockFace.UP, 2).getType();
Material down1 = block.getRelative(BlockFace.DOWN, 1).getType();
Material down2 = block.getRelative(BlockFace.DOWN, 2).getType();
// Concatenate the first letters of each of the materials
String materialFirstLetters = first(up1.toString()) + first(up2.toString()) +
first(main.toString()) + first(down1.toString()) +
first(down2.toString());
// Regex pattern
String regex = "DIJ..|I.DJ.|..IDJ";
// Check if the first letters of the materials match the regex pattern
if (materialFirstLetters.matches(regex))
{
System.out.println("Antenna Created");
}
}
For my final year project I had to build an n-tier web application from scratch using design patterns such as MVC, Command, Factory, Service, and DAO and technologies such as Java, JSP, JSTL, Tomcat, JUnit, XML, HTML/CSS, Javascript, MySQL.
Homepage. Displays featured books, latest books, newest members, and recent reviews.
All Books. Displays list of books which can be sorted by Title, Price, Rating, or Release Date.
Book (top). Shows the books title, image, rating and
Book (bottom). Shows similar themed books. Reviews by the users which can be filtered.
Profile. Shows profile of user and their recent reviews.