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

Commit

Permalink
Fixed the merging request
Browse files Browse the repository at this point in the history
  • Loading branch information
BigNocciolino committed Apr 20, 2021
1 parent 7d462e8 commit c00ae50
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@

public class acceptWarp {

static Player recivier;
static Player sender;
private warpreq req;

public acceptWarp(Player send, Player recv) {
recivier = recv;
sender = send;
public acceptWarp(warpreq request) {
this.req = request;
}

//TODO impostare il controllo del warp in classe a parte
public static boolean acceptRequest() {
warpreq req = warpreq.getRequestBySenderAndRecivier(sender, recivier);
public void acceptRequest() {

Player sender = req.getRequester();
Player recivier = req.getResponder();

if (req == null) {
return false;
sender.sendMessage("Sesso");
}else {
//Warp the player
//Warp the player1
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;
warpreq.warpTo(sender, recivier);
warpreq.removeRequest(req);
}else {
//Warp the recivier of the request to the sender
req.warpTo(recivier, sender);
warpreq.removeRequest(req);
//Request type = WPHERE
recivier.sendMessage("Ti stai warpando da " + recivier.getName());
sender.sendMessage(sender.getName() + " Si sta warpando da te");
return true;
warpreq.warpTo(recivier, sender);
warpreq.removeRequest(req);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ 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 Player recivier; //Player that receive the request
private Player sender; //Player that send request
private warpType type;

public warpreq(Player sender, Player recivier, warpType tpType) {
Expand Down Expand Up @@ -47,7 +47,7 @@ public static List<warpreq> getRequestsByRevier(Player recivier) {

public static warpreq getRequestBySenderAndRecivier(Player sender, Player recivier) {
for (warpreq req : requestlist) {
if (req.getRequester() == sender && req.getResponder() == recivier) {
if (req.getRequester() == recivier && req.getResponder() == sender) {
return req;
}
}
Expand All @@ -57,7 +57,7 @@ public static warpreq getRequestBySenderAndRecivier(Player sender, Player recivi
public static List<warpreq> getRequestBySender(Player sender) {
List<warpreq> requests = new ArrayList<>();
for (warpreq req : requestlist) {
if (req.getRequester() == sender) {
if (req.sender == sender) {
requests.add(req);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
Player target = Bukkit.getPlayer(args[0]);
if (target != null) {
if (target != p) {
//TOFIX
//FIX
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());
if (warpreq.getRequestBySender(p).size() >= 1) {
p.sendMessage("You have already sent a request to " + target.getName());
}else {
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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.minecraftplugin.Utils.warpRequest.Executor;

import com.minecraftplugin.Utils.warpRequest.Commands.acceptWarp;
import com.minecraftplugin.Utils.warpRequest.Commands.warpreq;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
Expand Down Expand Up @@ -29,16 +30,30 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
Player target = Bukkit.getPlayer(args[0]);
if (target != null) {
if (target != p) {
acceptWarp accept = new acceptWarp(target, p);
acceptWarp.acceptRequest();
warpreq req = warpreq.getRequestBySenderAndRecivier(p, target);
if (req != null) {
if (p == req.getResponder()) {
acceptWarp accept = new acceptWarp(req);
accept.acceptRequest();
}else {
p.sendMessage("Tou cannot accept your request");
}
}else{
p.sendMessage("There is no request");
}
}else {
p.sendMessage("Non hai richieste da accettare");
p.sendMessage("Why are you doing this");
}
}else {
p.sendMessage("Questo player non esiste");
}
}else {
//TODO accetta tutte le richieste verso di te
//Accept the last request
if (warpreq.getRequestBySender(p).size() == 1){
warpreq request = warpreq.getRequestBySender(p).get(0);
acceptWarp accept_all = new acceptWarp(request);
accept_all.acceptRequest();
}
}
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public boolean onCommand(CommandSender sender, Command command, String s, String
Player target = Bukkit.getPlayer(args[0]);
if (target != null) {
if (target != p) {
//TODO add one request only
warpreq req = new warpreq(p, target, warpreq.warpType.WARPHERE);
warpreq.addRequest(req);
p.sendMessage("Sent warp request to you at " + target.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import org.bukkit.entity.Player;

public class warpNo implements CommandExecutor {

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

Expand All @@ -16,11 +18,25 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
if (command.getName().equals("warpno")){
if (args.length > 0) {
Player target = Bukkit.getPlayer(args[0]);
warpreq req = warpreq.getRequestBySenderAndRecivier(p, target);
if (req.getRequester() == p) {
req.removeRequest(req);
if (target != null) {
if (target != p) {
warpreq req = warpreq.getRequestBySenderAndRecivier(p, target);
if (req != null) {
if (req.getResponder() == p) {
warpreq.removeRequest(req);
p.sendMessage("Declined request");
target.sendMessage(p.getName() + " declined your request");
} else {
p.sendMessage("You have no request from this player");
}
}else {
p.sendMessage("Tardino");
}
}else {
p.sendMessage("Ma si babb");
}
}else {
p.sendMessage("You have no request from this player");
p.sendMessage("Il player non esiste");
}
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/com/minecraftplugin/minecraftplugin/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import com.minecraftplugin.Completer.Tabcompleter;
import com.minecraftplugin.Executors.*;
import com.minecraftplugin.Utils.warpRequest.Executor.warpAccept;
import com.minecraftplugin.Utils.warpRequest.Executor.warpHereExecutor;
import com.minecraftplugin.Utils.warpRequest.Executor.warpList;
import com.minecraftplugin.Utils.warpRequest.Executor.*;
import com.minecraftplugin.data.data;
import com.minecraftplugin.Utils.warpRequest.Executor.WarpTo;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.logging.Logger;
Expand Down Expand Up @@ -40,7 +37,7 @@ public void onEnable() {
this.getCommand("warpaccept").setExecutor(new warpAccept());
this.getCommand("warphere").setExecutor(new warpHereExecutor());
this.getCommand("warplist").setExecutor(new warpList());
this.getCommand("warpno").setExecutor(new warpList());
this.getCommand("warpno").setExecutor(new warpNo());
this.saveDefaultConfig();
this.reloadConfig();
data = new data();
Expand Down
8 changes: 4 additions & 4 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Config file for all commands and possibilities
#If you have some isessues look at the source code https://github.com/PepegaBruh/EasyWarpPlugin
#If you have some issues look at the source code https://github.com/PepegaBruh/EasyWarpPlugin

#By default is set to true
#if is set to true only the owner of the warp can delete itself.
Expand All @@ -18,15 +18,15 @@ sendRequest: true

#By default you can't disable the request from a player to him

#Modify this to change the prefix of the messagies in the chat
#Modify this to change the prefix of the messages in the chat
#Dont remove the space at the end of the line, or everything will be written attached
messagiesPrefix: "&5[EasyWarp] "

messagies:
#In this section you can change the messagies for the warp
#In this section you can change the messages for the warp
#Chenge the number after the "&" to change the color
warp:
warped: "&6You warped yoursef"
warped: "&6You warped yourself"
notExist: "&6There is no warp with this name"
arg: "%cInsert a warp name"
permission: "&cYou not have this permission"
Expand Down

0 comments on commit c00ae50

Please sign in to comment.