Skip to content
This repository was archived by the owner on Nov 18, 2021. It is now read-only.

Commit

Permalink
added warp request
Browse files Browse the repository at this point in the history
  • Loading branch information
BigNocciolino committed Apr 15, 2021
1 parent 1c68a86 commit 7d462e8
Show file tree
Hide file tree
Showing 15 changed files with 390 additions and 99 deletions.
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ Use this plugin to teleport yourself to certain points of the map and the world

- warp.warpto | Enable the player to warp to other player

# General


## Installation
Install the ultimate release and put in your plugin folder in your minecraft server
and it will create all folders and files.
Expand Down
60 changes: 0 additions & 60 deletions src/main/java/com/minecraftplugin/Executors/WarpTo.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.minecraftplugin.Utils.warpRequest.Commands;

import org.bukkit.entity.Player;

public class acceptWarp {

static Player recivier;
static Player sender;

public acceptWarp(Player send, Player recv) {
recivier = recv;
sender = send;
}

//TODO impostare il controllo del warp in classe a parte
public static boolean acceptRequest() {
warpreq req = warpreq.getRequestBySenderAndRecivier(sender, recivier);
if (req == null) {
return false;
}else {
//Warp the player
if (req.getType() == warpreq.warpType.WARPTO) {
req.warpTo(sender, recivier);
warpreq.removeRequest(req);
sender.sendMessage("Ti stai warpando da " + recivier.getName());
recivier.sendMessage(sender.getName() + " Si sta warpando da te");
return true;
}else {
//Warp the recivier of the request to the sender
req.warpTo(recivier, sender);
warpreq.removeRequest(req);
recivier.sendMessage("Ti stai warpando da " + recivier.getName());
sender.sendMessage(sender.getName() + " Si sta warpando da te");
return true;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.minecraftplugin.Utils.warpRequest.Commands;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;

public class warpreq {

public static List<warpreq> requestlist = new ArrayList<>();

static Player recivier; //Player that receive the request
static Player sender; //Player that send request
private warpType type;

public warpreq(Player sender, Player recivier, warpType tpType) {
this.recivier = recivier;
this.sender = sender;
this.type = tpType;
}

public Player getRequester() {
return sender;
}

public Player getResponder() {
return recivier;
}

public warpType getType() {
return type;
}

public enum warpType {
WARPHERE,
WARPTO
}

public static List<warpreq> getRequestsByRevier(Player recivier) {
List<warpreq> requests = new ArrayList<>();
for (warpreq request : requestlist) {
if (request.recivier == recivier) {
requests.add(request);
}
}
return requests;
}

public static warpreq getRequestBySenderAndRecivier(Player sender, Player recivier) {
for (warpreq req : requestlist) {
if (req.getRequester() == sender && req.getResponder() == recivier) {
return req;
}
}
return null;
}

public static List<warpreq> getRequestBySender(Player sender) {
List<warpreq> requests = new ArrayList<>();
for (warpreq req : requestlist) {
if (req.getRequester() == sender) {
requests.add(req);
}
}
return requests;
}


public static void addRequest(warpreq request) {
requestlist.add(request);
}

public static void removeRequest(warpreq request) {
requestlist.remove(request);
}

public static void warpTo(Player send, Player recv) {
send.teleport(recv.getLocation());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.minecraftplugin.Utils.warpRequest.Commands;

import org.bukkit.entity.Player;

public class wpPending {

public static String pendingRequestsRecivier(Player recv) {
String requests;
requests = String.valueOf(warpreq.getRequestsByRevier(recv).size());
return requests;
}

public static String pendingRequestsSender(Player send) {
String requests;
requests = String.valueOf(warpreq.getRequestBySender(send).size());
return requests;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.minecraftplugin.Utils.warpRequest.Executor;

import com.minecraftplugin.Utils.warpRequest.Commands.warpreq;
import com.minecraftplugin.minecraftplugin.Main;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class WarpTo implements CommandExecutor {

/*
* Class for the exeecutor for the warp requeto to another player
*
* If tou send a request you can warp yourself to him only if it accept
*/

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

if (sender instanceof Player) {
//Player who send the request
Player p = (Player) sender;
if (args.length > 0) {
//Player who recive the request
Player target = Bukkit.getPlayer(args[0]);
if (target != null) {
if (target != p) {
//TOFIX
if (Boolean.parseBoolean(Main.getInstance().getConfig().getString("sendRequest"))) {
//Create a new request
warpreq request = new warpreq(p, target, warpreq.warpType.WARPTO);
//Add it
warpreq.addRequest(request);
p.sendMessage("Sent request to " + target.getName());
target.sendMessage("Recivied a requesto from " + p.getName());
}else {
warpreq.warpTo(p, target);
//TODO messagies
}
}else {
p.sendMessage("WTF are you doing WHY");
}
}else {
p.sendMessage("Questo player non esiste");
}
}else {
p.sendMessage("inserisci il nome del player a cui vuoi fare la richiesta");
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.minecraftplugin.Utils.warpRequest.Executor;

import com.minecraftplugin.Utils.warpRequest.Commands.acceptWarp;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class warpAccept implements CommandExecutor {

/*
* With this class you can handle the executor for accept a request pending to you
*
* (You accept to teleport the player tat sand to your location)
*/

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

//TODO messaggi custom yaml
if (sender instanceof Player ) {
//TODO switch to permission
if (command.getName().equals("warpaccept")) {
//Who accept
Player p = (Player) sender;
if (args.length > 0) {
//Who sended the request
Player target = Bukkit.getPlayer(args[0]);
if (target != null) {
if (target != p) {
acceptWarp accept = new acceptWarp(target, p);
acceptWarp.acceptRequest();
}else {
p.sendMessage("Non hai richieste da accettare");
}
}else {
p.sendMessage("Questo player non esiste");
}
}else {
//TODO accetta tutte le richieste verso di te
}
}
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.minecraftplugin.Utils.warpRequest.Executor;

import com.minecraftplugin.Utils.warpRequest.Commands.warpreq;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class warpHereExecutor implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String s, String[] args) {

if (sender instanceof Player) {
Player p = (Player)sender;
if (command.getName().equals("warphere")) {
if (args.length > 0) {
Player target = Bukkit.getPlayer(args[0]);
if (target != null) {
if (target != p) {
warpreq req = new warpreq(p, target, warpreq.warpType.WARPHERE);
warpreq.addRequest(req);
p.sendMessage("Sent warp request to you at " + target.getName());
target.sendMessage("Recivied warp request to him from " + p.getName());
}else {
p.sendMessage("WHYYYYYYYYYYYYYYYY");
}
}else {
p.sendMessage("Questo player non esiste");
}
}else {
p.sendMessage("Inserisci il nome del player");
}
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.minecraftplugin.Utils.warpRequest.Executor;

import com.minecraftplugin.Utils.warpRequest.Commands.wpPending;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

public class warpList implements CommandExecutor {


@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {

if (sender instanceof Player) {
Player p = (Player) sender;
if (command.getName().equals("warplist")) {
wpPending list = new wpPending();
p.sendMessage(wpPending.pendingRequestsSender(p));
p.sendMessage("To you " + wpPending.pendingRequestsRecivier(p));
}
return true;
}
return false;
}
}
Loading

0 comments on commit 7d462e8

Please sign in to comment.