Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tab補完(graycat27-patch-1)の修正 #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 0 additions & 36 deletions foofledrive.iml

This file was deleted.

14 changes: 6 additions & 8 deletions src/main/java/ga/ganma/ender/Listener/GetEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import ga.ganma.ender.Endercloud;
import ga.ganma.ender.Filerelation;
import ga.ganma.ender.inventoryRelation.InventoryAPI;
import ga.ganma.ender.plan;
import ga.ganma.ender.Plan;
import ga.ganma.ender.playerdata.Playerdata;
import jdk.internal.ref.Cleaner;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
Expand All @@ -14,7 +13,6 @@
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.Plugin;

import java.io.File;
import java.util.Calendar;
import java.util.HashMap;

Expand All @@ -30,7 +28,7 @@ public GetEvent(Plugin pl) {
public void getplayerloginEvent(PlayerJoinEvent e) {
Player p = e.getPlayer();
if (Filerelation.namecheck(p)) {
if (Filerelation.readFile(p).getPlan() == plan.FREE) {
if (Filerelation.readFile(p).getPlan() == Plan.FREE) {
p.sendMessage("[foofle drive]あなたは現在" + Filerelation.readFile(p).getPlan() + "プランに加入しています。");
return;
}
Expand All @@ -46,7 +44,7 @@ public void getplayerloginEvent(PlayerJoinEvent e) {
Endercloud.econ.depositPlayer(p, -amout[1]);
p.sendMessage("[foofle drive]LIGHTプランの料金を支払いました。");
} else {
InventoryAPI.planchange(p, plan.FREE);
InventoryAPI.planchange(p, Plan.FREE);
p.sendMessage("[foofle drive]お金が足りないため自動的にfreeプランへ移行しました。");
p.sendMessage("[foofle drive]その際、2段目以降にあるアイテムを全消去しました。");
}
Expand All @@ -56,7 +54,7 @@ public void getplayerloginEvent(PlayerJoinEvent e) {
Endercloud.econ.depositPlayer(p, -amout[2]);
p.sendMessage("[foofle drive]MIDDLEプランの料金を支払いました。");
} else {
InventoryAPI.planchange(p, plan.FREE);
InventoryAPI.planchange(p, Plan.FREE);
p.sendMessage("[foofle drive]お金が足りないため自動的にfreeプランへ移行しました。");
p.sendMessage("[foofle drive]その際、2段目以降にあるアイテムを全消去しました。");
}
Expand All @@ -66,7 +64,7 @@ public void getplayerloginEvent(PlayerJoinEvent e) {
Endercloud.econ.depositPlayer(p, -amout[3]);
p.sendMessage("[foofle drive]LARGEプランの料金を支払いました。");
} else {
InventoryAPI.planchange(p, plan.FREE);
InventoryAPI.planchange(p, Plan.FREE);
p.sendMessage("[foofle drive]お金が足りないため自動的にfreeプランへ移行しました。");
p.sendMessage("[foofle drive]その際、2段目以降にあるアイテムを全消去しました。");
}
Expand All @@ -89,7 +87,7 @@ public void getplayerloginEvent(PlayerJoinEvent e) {
}
}
else {
Playerdata pd = new Playerdata(p, Bukkit.getServer().createInventory(null, 9, "foofle Drive"), plan.FREE);
Playerdata pd = new Playerdata(p, Bukkit.getServer().createInventory(null, 9, "foofle Drive"), Plan.FREE);
Filerelation.createFile(pd);
p.sendMessage("[foofle drive]あなたは自動的に" + Filerelation.readFile(p).getPlan() + "プランに加入しました。");
}
Expand Down
55 changes: 55 additions & 0 deletions src/main/java/ga/ganma/ender/Plan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package ga.ganma.ender;

import java.io.Serializable;

public enum Plan implements Serializable {
FREE,LIGHT,MIDDLE,LARGE;

/**
* プラン名として有効な文字列か判定する
* @param arg プラン名(かもしれない)文字列
* @return 大文字小文字を意識せず、プラン名として有効な場合<code>true</code>。それ以外の場合<code>false</code>
*/
public static boolean isPlanName(String arg){
if(arg == null || arg.isEmpty()){
return false;
}
for(Plan p: Plan.values()){
if(arg.equalsIgnoreCase(p.name())){
return true;
}
}
return false;
}

/**
* 引数に対応するPlanを返す
* @param arg 取得したいPlan名
* @return 有効なPlan名の場合、対応するPlan。対応しない場合は<code>null</code>
*/
public static Plan getPlan(String arg){
if(isPlanName(arg)){
for(Plan p : Plan.values()){
if(p.name().equalsIgnoreCase(arg)){
return p;
}
}
}
return null;
}

/**
* Plan名の一覧を取得する
* @return カンマ区切りで列挙したPlan名の一覧
*/
public static String getPlanNameList(){
StringBuilder sb = new StringBuilder();
for(Plan p : Plan.values()){
if(sb.length() != 0){
sb.append(',');
}
sb.append(p.name());
}
return sb.toString();
}
}
71 changes: 38 additions & 33 deletions src/main/java/ga/ganma/ender/command/CommandMain.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package ga.ganma.ender.command;

import ga.ganma.ender.Filerelation;
import ga.ganma.ender.plan;
import ga.ganma.ender.Plan;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.List;
import java.util.logging.Level;

public class CommandMain implements CommandExecutor {
Expand All @@ -21,38 +23,41 @@ public CommandMain(Plugin pl) {

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender instanceof Player) {
Player p = (Player) sender;
if (label.equalsIgnoreCase("ec")) {
if (args.length != 0) {
if (args[0].equalsIgnoreCase("open")) {
new Subopen(this.pl, (Player) sender);
} else if (args[0].equalsIgnoreCase("plan")) {
if (args.length > 1) {
if (args[1].equalsIgnoreCase("LIGHT")) {
new Subplan(this.pl, p, plan.LIGHT);
Filerelation.readFile(p).setFinish(Calendar.getInstance());
} else if (args[1].equalsIgnoreCase("FREE")) {
new Subplan(this.pl, p, plan.FREE);
}else if (args[1].equalsIgnoreCase("MIDDLE")) {
new Subplan(this.pl, p, plan.MIDDLE);
}else if (args[1].equalsIgnoreCase("LARGE")) {
new Subplan(this.pl, p, plan.LARGE);
}
} else {
p.sendMessage("[foofle drive]プラン名を入力してください。");
p.sendMessage("[foofle drive]FREE,LIGHT,MIDDLE,LARGE");
}
}
}
else {
p.sendMessage("[free drive] /ec open でfoofle driveを開くことができます。");
p.sendMessage("[free drive] /ec plan で好きなプランに加入することができます。");
}
}
}
else {
if(!(sender instanceof Player)){
pl.getLogger().log(Level.FINE, "このコマンドはコンソールからではなくプレイヤーが入力するものです。");
return false;
}
if(!label.equalsIgnoreCase("ec")){
//not ec command
return false;
}

Player p = (Player) sender;
if(args.length == 0){
p.sendMessage("[foofle drive] /ec open でfoofle driveを開くことができます。");
p.sendMessage("[foofle drive] /ec plan で好きなプランに加入することができます。");
return false;
}

if (args[0].equalsIgnoreCase("open")) {
new Subopen(this.pl, (Player) sender);
} else if (args[0].equalsIgnoreCase("plan")) {
if(args.length == 1){ //入力不足
p.sendMessage("[foofle drive]プラン名を入力してください。");
p.sendMessage("[foofle drive]" + Plan.getPlanNameList());
return false;
}

Plan inputPlan = Plan.getPlan(args[1]);
if(inputPlan == null){ //入力値無効
p.sendMessage("[foofle drive]「"+ args[1] +"」は無効なプラン名です。");
p.sendMessage("[foofle drive] 有効なプラン名を入力してください。" + Plan.getPlanNameList());
}

new Subplan(this.pl, p, inputPlan);
if(inputPlan == Plan.LIGHT){
Filerelation.readFile(p).setFinish(Calendar.getInstance());
}
}
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/ga/ganma/ender/command/Subplan.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ga.ganma.ender.command;

import ga.ganma.ender.Filerelation;
import ga.ganma.ender.Plan;
import ga.ganma.ender.inventoryRelation.InventoryAPI;
import ga.ganma.ender.playerdata.Playerdata;
import org.bukkit.entity.Player;
Expand All @@ -11,7 +12,7 @@
public class Subplan {
Plugin pl;
Player p;
public Subplan(Plugin pl, Player player, ga.ganma.ender.plan plan){
public Subplan(Plugin pl, Player player, Plan plan){
this.pl = pl;
p = player;
InventoryAPI.planchange(player,plan);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ga.ganma.ender.inventoryRelation;

import ga.ganma.ender.Filerelation;
import ga.ganma.ender.plan;
import ga.ganma.ender.Plan;
import ga.ganma.ender.playerdata.Playerdata;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
Expand All @@ -17,7 +17,7 @@ public static Inventory Inventorysizechange(Inventory oldInv, int setsize){
return inv;
}

public static void planchange(Player player, plan plan){
public static void planchange(Player player, Plan plan){
Inventory inv = null;
ItemStack[] is = null;
switch (plan){
Expand Down
7 changes: 0 additions & 7 deletions src/main/java/ga/ganma/ender/plan.java

This file was deleted.

8 changes: 4 additions & 4 deletions src/main/java/ga/ganma/ender/playerdata/Playerdata.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ga.ganma.ender.playerdata;

import ga.ganma.ender.inventoryRelation.InventoryEncoder;
import ga.ganma.ender.plan;
import ga.ganma.ender.Plan;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;

Expand All @@ -11,17 +11,17 @@

public class Playerdata implements Serializable {
private UUID mcid;
private plan plan;
private Plan plan;
private String inventorySt;
private Calendar finish;

public Playerdata(Player pl, Inventory inv, plan plan) {
public Playerdata(Player pl, Inventory inv, Plan plan) {
this.mcid = pl.getUniqueId();
this.plan = plan;
this.inventorySt = InventoryEncoder.inventoryToString(inv);
}

public ga.ganma.ender.plan getPlan() {
public Plan getPlan() {
return plan;
}

Expand Down
24 changes: 22 additions & 2 deletions src/main/java/ga/ganma/foofledrive/Foofledrive.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

import ga.ganma.foofledrive.Listener.GUIEvent;
import ga.ganma.foofledrive.Listener.GetEvent;
import ga.ganma.foofledrive.bukkitRunnable.Runnable;
import ga.ganma.foofledrive.command.CommandMain;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.util.UUID;
import java.util.logging.Logger;

public final class Foofledrive extends JavaPlugin {
Expand All @@ -29,6 +32,8 @@ public void onEnable() {
new GUIEvent(this);
this.getCommand("fl").setExecutor(new CommandMain(this));
this.getCommand("foofledrive").setExecutor(new CommandMain(this));
this.getCommand("fl").setTabCompleter(new CommandMain(this));
this.getCommand("foofledrive").setTabCompleter(new CommandMain(this));
saveDefaultConfig();
configamout[0] = this.getConfig().getInt("amout.FREE");
configamout[1] = this.getConfig().getInt("amout.LIGHT");
Expand All @@ -40,7 +45,22 @@ public void onEnable() {
Bukkit.getLogger().warning("[foofle drive]Vaultが存在しません!");
return;
}
new Runnable(this).runTaskTimer(this,0,20);

String FS = File.separator;
File folder = new File(getDataFolder() + FS + "playerdata");
if (folder.exists()) {
File[] list = folder.listFiles();
if (list != null) {
for (File f : list) {
String name = f.getName();
name = name.substring(0, name.lastIndexOf('.'));
UUID id = UUID.fromString(name);
OfflinePlayer pl = Bukkit.getOfflinePlayer(id);
ga.ganma.foofledrive.economy.Economy.paymoney(pl);
}

}
}
}

@Override
Expand Down
Loading